Sorry if this is a stupid noob question please be gentle with me I’m trying to learn…
I want to test against the attribute methods of things like models and controllers. Mostly to make sure they have the right attrbute ie Required. But i’m also using this as an experiment with extension methods and Lambdas.
What I’d like is a method that when implimented looks some thing like
Controller controller = new Controller();
controller.MethodName(params).HasAttribute<AttributeName>();
Iveused extension methods a little but not to this degree.. I’m sure this should be simple enough to do but cant seem to get my generics etc correct.
Perhaps you are looking for this:
What’s nice about writing it like this is that you have fully compile time support. All other solutions thus far use string literals to define the methods.
Here are the implementations of the
GetMethodandHasAttribute<T>extension methods: