Solved

Custom Attribute and visibility of the object it is attached to

Posted on 2008-10-21
1
285 Views
Last Modified: 2012-05-05
Hi,

If I create a custom attribute how can I access the Property it wraps.  So basically the scope of the attribute I am crating is only for properties but I assume that the answer to this will probably answer how a method or class attribute can get access to the method or class IT wraps.

So if I have a property called MyProperty and a custom attribute called MyAttribute.  How can MyAttribute see the property MyProperty.

TIA

Andrew
0
Comment
Question by:REA_ANDREW
1 Comment
 
LVL 13

Accepted Solution

by:
crazyman earned 500 total points
ID: 22768265
Attribues are attached to the type, not an instance.

When you go

typeof(MyType).GetCustomAttributes ... etc

This will get you instances of your attributes but no instances of MyType exist here, so from within your attribute class there is no parent instance of the class it belongs to, i expect its possible to get the PropertyInfo object about the property it is attached to..
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question