Re static in attributes

P

Pohihihi

Actually I am not understanding what you mean by
attribute will not be applicable to the type, but rather, all types

you mean it will behave like
[AttributeUsage(AttributeTargets.All)]

??

Thanks,
Po

Nicholas Paldino said:
Pohihihi,

Attributes can have static methods/properties, just like any other
class. However, you have to remember that a static method/property on an
attribute will not be applicable to the type, but rather, all types.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Pohihihi said:
In what condition attributes (class) might have static methods?
 
N

Nicholas Paldino [.NET/C# MVP]

Pohihihi,

No, what I meant was that instance properties and methods on an
attribute have the scope of the thing they are applied to (let's assume we
are talking about a class here for a moment).

With static members, those are applicable to everything. Remember, an
attribute is applied to a type, or part of a type, and becomes part of the
metadata for that type. If you are going to add static members to an
attribute, make sure it is designed properly.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Pohihihi said:
Actually I am not understanding what you mean by
attribute will not be applicable to the type, but rather, all types

you mean it will behave like
[AttributeUsage(AttributeTargets.All)]

??

Thanks,
Po

in
message news:%[email protected]...
Pohihihi,

Attributes can have static methods/properties, just like any other
class. However, you have to remember that a static method/property on an
attribute will not be applicable to the type, but rather, all types.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Pohihihi said:
In what condition attributes (class) might have static methods?
 
P

Pohihihi

Thanks for the reply Nicholas but I guess I am still not getting what you
mean. I understand that attrib do things like class and having static
methods will behave like a class static but what is the use and how it is
applied is still a question for me. Are there any links that I might go
throw to understand the deep concepts?



Nicholas Paldino said:
Pohihihi,

No, what I meant was that instance properties and methods on an
attribute have the scope of the thing they are applied to (let's assume we
are talking about a class here for a moment).

With static members, those are applicable to everything. Remember, an
attribute is applied to a type, or part of a type, and becomes part of the
metadata for that type. If you are going to add static members to an
attribute, make sure it is designed properly.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Pohihihi said:
Actually I am not understanding what you mean by
attribute will not be applicable to the type, but rather, all types

you mean it will behave like
[AttributeUsage(AttributeTargets.All)]

??

Thanks,
Po

in
message news:%[email protected]...
Pohihihi,

Attributes can have static methods/properties, just like any other
class. However, you have to remember that a static method/property on
an
attribute will not be applicable to the type, but rather, all types.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

In what condition attributes (class) might have static methods?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top