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

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

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -