由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DotNet版 - 有人可以谈谈对于attribute的理解嘛?
相关主题
Mutually exclusive attributesNamed Parameters
C# on JVM?mvc pros and cons
cs unit 范例如何用ajax实现comments update
哪位推荐一下关于Reflection/C# attribute的资料 Threading Question
麻烦大家帮忙看看:cannot find dependencyC#.Net Funsdamentals (3)
请教一个HTMLelement问题C#.Net Funsdamentals (4)
What's the difference between ToolsVersion and Target Framework?c#有没有第三方地免费解释器?
how to make javascript/jquery in asp.net running fast? Thank you![转载] 装了Visual Studio 6.0后IE常常出错
相关话题的讨论汇总
话题: attribute话题: attributes话题: runtime话题: semantics话题: some
进入DotNet版参与讨论
1 (共1页)
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.

1 (共1页)
进入DotNet版参与讨论
相关主题
[转载] 装了Visual Studio 6.0后IE常常出错麻烦大家帮忙看看:cannot find dependency
R6029 Error With Cyrstal Report请教一个HTMLelement问题
.NET Runtime Optimization Service v2.0.50727_X86What's the difference between ToolsVersion and Target Framework?
.Net runtime errorhow to make javascript/jquery in asp.net running fast? Thank you!
Mutually exclusive attributesNamed Parameters
C# on JVM?mvc pros and cons
cs unit 范例如何用ajax实现comments update
哪位推荐一下关于Reflection/C# attribute的资料 Threading Question
相关话题的讨论汇总
话题: attribute话题: attributes话题: runtime话题: semantics话题: some