Solved

Custom Attribute and visibility of the object it is attached to

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

707 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