c# - Is it a bug that Delegate.CreateDelegate cannot bind to struct member overrides? -
after following answer on discovered have use ref
parameter call instance method on structs. how can create open delegate struct's instance method?
i cannot seem bind method overrides explicit interface implementations (to avoid boxing penalty associated, (which overrides far il concerned)), here bug report saying in future version of .net, can bind interface members found on struct: https://connect.microsoft.com/visualstudio/feedback/details/574959/cannot-create-open-instance-delegate-for-value-types-methods-which-implement-an-interface?wa=wsignin1.0#details
but trying bind members equals
,gethashcode
,or tostring
leads errors e.g.
public struct { public override int gethashcode(){/*implementation goes here*/} } delegate tret funcbyref<tstruct,tret>(ref tstruct) tstruct:struct
...
delegate.createdelegate(typeof(funcbyref<a,int>),typeof(a).getmethod("gethashcode"));
will fail exception "error binding target method".
how letting compiler worry it, i.e.
public static string somehelper(a obj) { return obj.somemethod(); }
then bind instead "somehelper". generic method of needed, use magic "constrained" opcode.
this similar to
func<a string> func = obj => obj.somemethod();
if usig reflection method might try dynamicmethod.
Comments
Post a Comment