Is this an error that Delegate.CreateDelegate cannot associate with overriding structure elements?

After answering this, I found that I needed to use a parameter refto call the instance method in structs. How to create an open delegate from an instance method of a structure?

I can’t be attached to method overrides, for example, to explicit implementations of the interface (in order to avoid a related penalty for boxing (which are really redefined with respect to IL)) Here is an error report that says that in a future version of .NET we can bind to the interface elements found in the structure: 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 even an attempt to bind to type elements Equals, GetHashCodeor ToStringleads to errors for example.

public struct A
{
     public override int GetHashCode(){/*implementation goes here*/}
}
delegate TRet FuncByRef<TStruct,TRet>(ref TStruct) where TStruct:struct

...

Delegate.CreateDelegate(typeof(FuncByRef<A,int>),typeof(A).GetMethod("GetHashCode"));

will fail with the error "Binding to the target method".

+5
source share
1

, , ..

public static string SomeHelper(A obj) {
    return obj.SomeMethod();
}

"SomeHelper". , , "" .

Func<A string> func = obj => obj.SomeMethod();

usig , DynamicMethod.

0

All Articles