?
Solved

Custom Attribute and visibility of the object it is attached to

Posted on 2008-10-21
1
Medium Priority
?
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 13

Accepted Solution

by:
crazyman earned 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

765 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