Attribute is essentially a description of various elements in C #. The types of elements are as follows:
Descriptive elements
Public Enum Attributetargets
{
All = 16383 ,
Assembly = 1 ,
Module = 2 ,
Class = 4 ,
Struct = 8 ,
Enum = 16 ,
Constructor = 32 ,
Method = 64 ,
Property = 128 ,
Field = 256 ,
Event = 512 ,
Interface = 1024 ,
Parameter = 2048 ,
Delegate = 4096 ,
Returnvalue = 8192
}
Different from other descriptive information, attribute itself is a class, so it can be obtained at runtime. It is a more elegant and consistent method for attaching declarative information to the runtime entity, these attributes can be used to implement further functions during runtime. in attribute. the application (III) (iv) in net programming provides an example of using attribute to call the sqlsever stored procedure, reflecting the advanced usage of attribute. Attribute can also be used for message listening. NET Programming Application (5) (6), there is an example for your reference, but it involves a lot of explanations about the message listening mechanism in C #, which is very confusing, it is difficult to understand.
For the basic usage of attribute, refer to attributes or application of attribute in. NET programming. Attribute is also widely used in nunit. Its intervention makes nunit more intuitive and easier to use than JUnit's naming conventions. The impact of. Net attribute on unit testing is described in detail.
References
Application of attribute in. NET Programming (1) (2) (3) (4) (5) (6)