Using system;
Using system. reflection;
Public class test
{
Public static void main ()
{
Testattribute TA = new testattribute ();
Type type = TA. GetType ();
Helpattribute help;
Foreach (attribute ATTR in type. getcustomattributes (true ))
{
Help = ATTR as helpattribute;
If (null! = Help)
{
Console. writeline (HELP. Description );
Help. Description = "the value has changed .";
Console. writeline (HELP. Description );
Console. Readline ();
}
}
Foreach (attribute ATTR in type. getcustomattributes (true ))
{
Help = ATTR as helpattribute;
If (null! = Help)
{
Console. writeline (HELP. Description );
Console. Readline ();
}
}
}
}
[Help ("the origin value")]
Public class testattribute
{
}
[Attributeusage (attributetargets. Class | attributetargets. method, allowmultiple = true, inherited = true)]
Public class helpattribute: attribute
{
Public helpattribute (string descrition_in)
{
This. Description = descrition_in;
}
Protected string description;
Public String description
{
Get
{
Return this. description;
}
Set
{
This. Description = value;
}
}
}
After running the above code, you can see that the answer is no,
The running result of this Code is:
The origin Value
The value has changed
The origin Value
We can see that attribute can change its value like a general class, but it is not the entity of attach in the testattribute class. I Want To (reflection and accessories I just started to study) reflect takes the attivity class entity of the attach class in the testattribute class out the read value, and creates another attribute entity when writing the attribute value. The above is just my test thought. It is absolutely wrong, correct your skills. Ah, you must learn Il, read the decompiled code, and see how. Net Works.
A netizen posted a post on csdn a few days ago and asked if a widget could change a property and affect the display of other attributes, [browsable (false)] is used to control the display. I answered the question based on my experience. This is a description. Later I thought that attribute is also a class, attributes may also be writable, so we did the above test.