Solved

Custom Attribute and visibility of the object it is attached to

Posted on 2008-10-21
1
283 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now