Attribute first is a class, in C #, Attribute is a compiler command to process in .NET, attribute is very important, whether it is writing a web control or a web service, the effect of the property is almost indispensable, and the sequence .. The program installation characteristics are more inseparable, it looks very mysterious. It is not difficult to write a property that belongs to her own. There are similar exemplary code on CodeProject and C # Corner. This is just a normal property, if AOP, you need to inherit from ContextAttribute, about AOP and ContextAttribute, and later articles will be specifically described, and there is also an associated example on Code Project;
namespace Test {// Only allow this attribute to be added to classes [AttributeUsage (AttributeTargets.Class)] public class TestAttribute: Attribute {// A number with some imaginary importance public int TheNumber;
// a String That Could Be Useful Somewhere Public String Name
////> Thenumber be set public testattribute (int kiln) {this.Thenumber = THENUMBER; Name = "none";
//Method to illustrate That An Attribute Is Really Just // a Class At Heart. This Will Be Used In Driver.cs Public Void Print () {Console.writeline ("/ Tthenumber = {0}", theenumber; console. WriteLine ("/ TNAME = /" {0} / "", name); The application range of this property is, for example, is applied to the method or a class or all applicable. In the above code, set this property that can only be used to use your own properties in your own class, such as [ Test (4, name = "testclassb")] Public class testmyatt {}, first in the construction method of the TestAttribute class, you need to initialize the Heumber property, so when you use TestAttribute, you must have an integer value, and Name is based on actual The situation may have no realization of its own attributes. In fact, it is also very beneficial to realize AOP mode.