Metadata (2)

xiaoxiao2021-03-06  43

Using system;

Namespace consoleApplication2 {///

/// Class1 Summary Description. /// class class1 {/// /// The primary entry point of the application. /// [STAThread] static void Main (string [] args) {System.Reflection.MemberInfo info = typeof (Cat); Color colorA = (Color) Attribute.GetCustomAttribute (info, typeof (Color)); IF (Colora! = null) {Console.writeLine ("Color of cat is: {0}", colora.color);}

INFO = TypeOf (Animal); colora = (color) Attribute.getCustomAttribute (IF (Colora! = null) {Console.Writeline ("Color of Animal IS: {0}", Colora.color }

}} [AttributeUSAGETS.CLIC Class Color: Attribute {Public String Color; Public Color (String Color) {this.color = color;}

}

[Color ("Red")] public class animal {}

[Color ("Blue")] public class cat: animal {} [color ("YELLOW")] public class dog: animal {}

} What this thing is to mean, there is a metadata called colors. There is a thing called animals, her color is red. There is a kind of animal called a cat, he is blue. There is a dog called a dog, he is yellow.

转载请注明原文地址:https://www.9cbs.com/read-55698.html

New Post(0)