c# - Convert Func<DerivedType, Object> to Func<BaseType, Object> -


what best way convert delegate takes first parameter of derived type 1 receives base type? mean is:

func<derivedtype, object> original = ...; func<basetype, object> converted = something(original); 

casts, of course, not work, since these 2 different types.

since want pass base type method takes derived type, need add cast. if know calls converted passing derivedtype, make straightforward wrapper, this:

func<basetype,object> converted = b => original((derivedtype)b); 

demo.


Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -