dimanche 21 août 2016

Pass method as param via expression

I need to have the ability to pass a method of my class (or base-class) to be passed to a base-class method (as it will have to do some more stuff there).

I known about the following posibility: In my base-class I have the method public void Call(Action action) which will simply call action() and do other stuff.

But I wan't some more restrictive as by now I can put everything in this method, e.g. Call(() => string.Format("Some {0}, "text)); But I only want to allow methods of own type or base-type.

I think about something like public void Call(Expression<Func<MyClassType, Action>> expressionToAction) but I don't get the right point here.

Is this even possible? With the expression-param I get the error that the method must return Action which is totally not what I want.





Aucun commentaire:

Enregistrer un commentaire