I created an EvaluateAttribute, and I want it to accept various IEvaluators specified like this:
[Evaluate(CatEvaluator, DogEvaluator)]
public void someMethod()
{
}
Since CatEvaluator and DogEvaluator are types, I set up my attribute class like this:
public class EvaluateAttribute<T> : Attribute where T:IAccessEvaluator
and constructor:
public EvaluateAttribute(params T [] accessEvaluators)
{
_accessEvaluators = accessEvaluators;
}
C# doesn’t like generics and attributes though, it would seem. Is there a solution to this?
I want my attribute to instantiate each type with CreateInstance and run an evaluate method specific in IAccessEvaluator.
You probably don’t need to use generics if you just want to pass classes implementing
IAccessEvaluator. Just change the signature toReread your question. You’re using types like objects, so my first impression was to write the above answer. If you need to annotate types, you should have a look at the comment on your question (by MUG4N).
and change
_accessEvaluatorstoType[]