您好,登錄后才能下訂單哦!
在C#中,元數(shù)據(jù)(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#中實現(xiàn)元數(shù)據(jù)的標準化。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。