您好,登錄后才能下訂單哦!
在C#中,元數據(metadata)通常是指程序集、類型、方法等的信息
using System;
using System.Reflection;
class Program
{
static void Main()
{
Assembly assembly = typeof(Program).Assembly;
Console.WriteLine("Assembly: " + assembly.FullName);
Type type = typeof(Program);
Console.WriteLine("Type: " + type.FullName);
MethodInfo method = typeof(Program).GetMethod("Main");
Console.WriteLine("Method: " + method.Name);
}
}
using System;
[AttributeUsage(AttributeTargets.Class)]
public class CustomAttribute : Attribute
{
public string Author { get; set; }
public string Version { get; set; }
}
[CustomAttribute(Author = "John Doe", Version = "1.0")]
class Program
{
static void Main()
{
Type type = typeof(Program);
CustomAttribute attribute = (CustomAttribute)type.GetCustomAttribute(typeof(CustomAttribute));
Console.WriteLine("Author: " + attribute.Author);
Console.WriteLine("Version: " + attribute.Version);
}
}
///<summary>
/// Represents a sample class.
/// </summary>
public class SampleClass
{
///<summary>
/// Adds two integers and returns the result.
/// </summary>
///<param name="a">The first integer.</param>
///<param name="b">The second integer.</param>
///<returns>The sum of the two integers.</returns>
public int Add(int a, int b)
{
return a + b;
}
}
通過以上方法,可以在C#中實現元數據的標準化。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。