Redian新闻
>
有人可以谈谈对于attribute的理解嘛?
avatar
有人可以谈谈对于attribute的理解嘛?# DotNet - 窗口里的风景
a*l
1
看了inside C#,
还是不明白attribute是拿来干吗的。
是一个自包含的,可以描述自己的说明嘛。
谢谢!
avatar
e*g
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是拿来干吗的。
: 是一个自包含的,可以描述自己的说明嘛。
: 谢谢!

avatar
k*i
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是拿来干吗的。
: 是一个自包含的,可以描述自己的说明嘛。
: 谢谢!

avatar
k*i
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.

avatar
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.

avatar
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:

avatar
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.

avatar
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.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。