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);
Comments
Post a Comment