Reflection: Get type signed with attribute

  • Thread starter Thread starter Markus Wildgruber
  • Start date Start date
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
 
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
 
Back
Top