在C#中,可以使用注解(Attribute)来为实体类添加元数据信息。可以使用以下步骤来为实体类添加注解:
[AttributeUsage(AttributeTargets.Class)] public class MyCustomAttribute : Attribute { public string Description { get; set; } public MyCustomAttribute(string description) { Description = description; } }
[MyCustomAttribute("This is a custom attribute")] public class MyClass { // class implementation }
MyCustomAttribute attribute = (MyCustomAttribute)Attribute.GetCustomAttribute(typeof(MyClass), typeof(MyCustomAttribute)); if (attribute != null) { Console.WriteLine(attribute.Description); }
通过以上步骤,可以为C#实体类添加注解并使用注解中的元数据信息。