a*****l 发帖数: 5 | 1 看了inside C#,
还是不明白attribute是拿来干吗的。
是一个自包含的,可以描述自己的说明嘛。
谢谢! |
e***g 发帖数: 158 | 2 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.
【在 a*****l 的大作中提到】 : 看了inside C#, : 还是不明白attribute是拿来干吗的。 : 是一个自包含的,可以描述自己的说明嘛。 : 谢谢!
|
k****i 发帖数: 1072 | 3 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.
【在 a*****l 的大作中提到】 : 看了inside C#, : 还是不明白attribute是拿来干吗的。 : 是一个自包含的,可以描述自己的说明嘛。 : 谢谢!
|
k****i 发帖数: 1072 | 4 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 发帖数: 2324 | 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 发帖数: 158 | 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 发帖数: 5 | 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 发帖数: 2300 | 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.
|