Getting all types that implement a custom attribute
hey, is using Assembly.GetTypes() and iterating them really the best way to get all types that implement a custom attribute? i was thinking i could just have a static enumerable in the attribute class like so:
7 Replies
Isn't "this" just the attribute itself?
cant you access the type via the attribute? idk attributes are kinda confusing for me since im more used to c/c++
You use the word implementing but I assumed you meant "decorated with"
yeah
basically ive got a state machine and atm states need to be registered manually
but i was thinking i could use an attribute to do somethingl ike
No you can't access the type the attribute is decorating from within the attribute as far as I know
It's possible I'm wrong but "this" definitely doesn't mean that
thats aight
i was just trying to simplify something that already works so its no biggie
thanks
you need to use reflection and find all public types that have this attribute. There is a method on
Type
for the "has my attribute" part.