Reflection: Get type signed with attribute

M

Markus Wildgruber

Hi!

We defined an attribute that can be applied to a type multiple times
(AllowMultiple = true). A type can have numerous instances of that attribute
that it may have inherited from its base classes.
Problem: If we have an instance of that attribute how can we find out which
class originally was signed with that specific instance.
E.g:

[AttributeUsage( AttributeTargets.Class, AllowMultiple = true )]
public class MyAttribute : Attribute
{
public MyAttribute( int intVal ) { ... }
}

[My(1)]
class Base
{
}

[My(2)]
class Child : Base
{
}

So Child is signed with My(1) and also My(2). If we have My(1), how can we
get the type that was signed with My(1), in this case Base.

TIA,

Markus
 
M

Mattias Sjögren

Markus,
Problem: If we have an instance of that attribute how can we find out which
class originally was signed with that specific instance.

You can't, unless you pass that information to the attribute instance
yourself.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top