This may be more of a design question then a “Can I do this?” question. I’m creating an attribute which its target is defined as Method. Is there any possible way to impose restrictions on the domain of methods,i.e that the target method must be declared abstract, virtual, static, etc?
The ultimate goal is to scan for these methods and implement them in a subclass–however I’d like them to be abstract. Is there a better way to accomplish this psuedo-restriction on targets of my attribute?
You should be able to filter out non-virtual methods which are decorated with your attribute using
MethodInfo.IsVirtualandMethodInfo.IsAbstractto get determine if it is abstract.There are ways to detect the other constraints you listed as well and the approach should be similar.
EDIT: Fixed to answer the question for methods.