Is there any way to get the instance class inside the attribute codein C#?
public class MyAttirbute : Attribute {
public someMethod(){
this.InstanceClass????
}
}
Is there any way to get the instance class inside the attribute codein C#?
public class MyAttirbute : Attribute {
public someMethod(){
this.InstanceClass????
}
}
No, unfortunately not.
Attributes are per type and per member (ie. per "something" they're attached to), not per instance.
You could even inspect the attributes and call those methods on it without there ever being any instances of the class it has been applied to.
What are you trying to do that requires this?
If I understand you correctly, you want to get the Type ("class") where an attribute is applied on.
This information is not available unfortunately, but you can only obtain it the other way around using reflection by visiting all types in an assembly and getting their custom attributes.