471,347 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,347 software developers and data experts.

Question about attributes

Hello.

How can I create attribute and specify that it can be applied only to the
non private fields or properties?

Thank you
Feb 14 '06 #1
2 924
David Dvali <da*********@hotmail.com> wrote:
How can I create attribute and specify that it can be applied only to the
non private fields or properties?


You can't, I'm afraid. You can specify that it can only be applied to
properties and fields, but you can't force them to be non-private ones.

However, it wouldn't be hard to write a verification tool which loaded
an assembly, scanned all the types for the attribute being applied, and
checked the accessibility of the fields/properties which had the
attribute.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 14 '06 #2
You can use the AttributeUsage attribute to indicate that the custom
attribute is applicable only to fields and properties, although I'm not sure
if there's a way to specify which access modifiers are valid.
http://msdn.microsoft.com/library/de...ibuteusage.asp

--
Tim Wilson
..NET Compact Framework MVP

"David Dvali" <da*********@hotmail.com> wrote in message
news:e$*************@TK2MSFTNGP10.phx.gbl...
Hello.

How can I create attribute and specify that it can be applied only to the
non private fields or properties?

Thank you

Feb 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by SB | last post: by
6 posts views Thread by Tim Mavers | last post: by
6 posts views Thread by Developer | last post: by
10 posts views Thread by jojobar | last post: by
1 post views Thread by Marcel Hug | last post: by
11 posts views Thread by Doru Roman | last post: by
28 posts views Thread by Alan Isaac | last post: by
4 posts views Thread by RobG | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.