Reputation: 123
I have a attribute class (inheriting Attribute), inside which I have a method which calls a generic method:
memberInfo.GetCustomAttribute<T>();
How can I pass current class type into T? I don't want to hard type the class name inside as it may be inherited and then it will not work.
Upvotes: 0
Views: 411
Reputation: 4164
below should work :
memberinfo.GetType().GetMethod("GetCustomAttribute").MakeGenericMethod(t).Invoke(instance, new object[] { 'yourMethodParameter'} )
Upvotes: -1
Reputation: 249636
You can use the version that takes Type
, not the generic version :
memberInfo.GetCustomAttribute(this.GetType());
Upvotes: 5