Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it a bug that Delegate.CreateDelegate cannot bind to struct member overrides?
    primarykey
    data
    text
    <p>After following the answer on this I discovered that I have to use a <code>ref</code> parameter to call instance method on structs. <a href="https://stackoverflow.com/questions/4326736/how-can-i-create-an-open-delegate-from-a-structs-instance-method/4327011#4327011">How can I create an open Delegate from a struct&#39;s instance method?</a></p> <p>I cannot seem to bind to method overrides like explicit interface implementations (to avoid the boxing penalty associated, (which are really overrides as far as the IL is concerned)), Here is a bug report saying that in a future version of .NET, we can bind to interface members found on a struct: <a href="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" rel="nofollow noreferrer">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</a></p> <p>But even trying to bind to members like <code>Equals</code>,<code>GetHashCode</code>,or <code>ToString</code> leads to errors e.g.</p> <pre><code>public struct A { public override int GetHashCode(){/*implementation goes here*/} } delegate TRet FuncByRef&lt;TStruct,TRet&gt;(ref TStruct) where TStruct:struct </code></pre> <p>...</p> <pre><code>Delegate.CreateDelegate(typeof(FuncByRef&lt;A,int&gt;),typeof(A).GetMethod("GetHashCode")); </code></pre> <p>will fail with the exception "Error binding to target method".</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload