在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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。