you don't feel need it, until you do reflective programming, make some magic framework, or design some language tools. newbies can just use provided predefined attributes as if they were part of language core.
I think it's helpful when you want to store some information within the metadata of the assembly and use the reflection class to get it back at runtime for some purpose.And I remember that it's also used in the .net security control like the code access control.Not quite sure about that part yet.
and also there are bunch of pre-defined attributes there to help compilation control,com interop control,etc.
【在 k****i 的大作中提到】 : I think it's helpful when you want to store some information within the : metadata of the assembly and use the reflection class to get it back at : runtime for some purpose.And I remember that it's also used in the .net : security control like the code access control.Not quite sure about that part : yet.
C*n
5 楼
You can think about Attribute this way: Category 1: 1. They are the same as static const. 2. They have to be accessed in a different way. (GetCustomAttributes) 3. They are not as effecient as static const variables, but they are less resource demanding. Since usually they are not loaded into memory until you use them especially. ============================================ Category 2: Magic pre-built-in Attributes: These stuff are bullshit, it's just a replacement of the compiler directive in
【在 k****i 的大作中提到】 : and also there are bunch of pre-defined attributes there to help compilation : control,com interop control,etc.
e*g
6 楼
ThreadStatic should be a runtime thing (well it could be done by compiler but its semantics is runtime) it's very wrong to use Attribute for it though. variable access is core semantics, the behavior shouldn't be modified by an attribute. and u think there are only a limimted set of such Attributes? MS must have tons of them internally. i heard some.
【在 C****n 的大作中提到】 : You can think about Attribute this way: : Category 1: : 1. They are the same as : static const. : 2. They have to be accessed in a different way. (GetCustomAttributes) : 3. They are not as effecient as static const variables, but they are less : resource demanding. Since usually they are not loaded into memory until you : use them especially. : ============================================ : Category 2:
a*l
7 楼
Thank u all guy!:)
ThreadStatic should be a runtime thing (well it could be done by compiler but its semantics is runtime) it's very wrong to use Attribute for it though. variable access is core semantics, the behavior shouldn't be modified by an attribute. and u think there are only a limimted set of such Attributes? MS must have tons of them internally. i heard some.
【在 e***g 的大作中提到】 : ThreadStatic should be a runtime thing (well it could be done by : compiler but its semantics is runtime) : it's very wrong to use Attribute for it though. variable access is : core semantics, the behavior shouldn't be modified by an attribute. : and u think there are only a limimted set of such Attributes? : MS must have tons of them internally. i heard some.
k*r
8 楼
One use of attributes is you may enumerate all the attributes of the .net type which you are mostly concerned about, then you may get some info of the type. For example, the predefined DecriptionAttribute may give you an idea what the type do.
part
【在 k****i 的大作中提到】 : and also there are bunch of pre-defined attributes there to help compilation : control,com interop control,etc.