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

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -