Solved

Custom Attribute and visibility of the object it is attached to

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

13 Experts available now in Live!

Get 1:1 Help Now