Tanque
Tanque

Reputation: 315

Is there a way to access attributes in the class of a property with said attribute?

In this scenario:

class MyClass
{
  [MyAttribute("flag")]
  public OtherClass Property {get; set;)

  // etc.
}

Is there a way for code in OtherClass to access the "flag" without knowledge of MyClass?

Upvotes: 0

Views: 45

Answers (1)

TomTom
TomTom

Reputation: 62157

Nope. Because OtherClass is totally independent and does not know where it is used. Well, in theory - yes. Load ALL classes, go through them, find all references, analyze for attribute via reflection. Depending on size and locality (in one assembly, in all assemblies) this may be slow or "oh damn, waht happened it is REALLLY slow", but yes, you can get access to all assemblies, all classes and use reflection on those.

Upvotes: 1

Related Questions