Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This answer is to elborate my thoughts on this interesting problem. Not a real answer, but a contribution to the whole discussion that is <strong>too small for a normal comment</strong>.</p> <p>I checked a few things, this interface:</p> <pre><code>namespace DifferentAssemblyNamespace { public interface IBar { event Action&lt;dynamic&gt; OnSomeEvent; } } </code></pre> <p>and its implementation:</p> <pre><code>// implicit interface implementation // generates compile error "Explicit interface implementation" public class Foo1 : IBar { private Action&lt;dynamic&gt; foo; public event Action&lt;dynamic&gt; OnSomeEvent { add { foo += value; } remove { foo -= value; } } } // implicit interface implementation // generates compile error "Not supported by the language" public class Foo2 : IBar { private Action&lt;dynamic&gt; foo; event Action&lt;dynamic&gt; IBar.OnSomeEvent { add { foo += value; } remove { foo -= value; } } } </code></pre> <p><strong>will never work</strong>, seems that one rule is excluding the other necessary rule.</p> <p><strong>but..</strong> if we call generics for help, and use a <strong>Type parameter</strong> instead of using <code>dynamic</code> directly like:</p> <pre><code>namespace DifferentAssemblyNamespace { public interface IGenericBar&lt;T&gt; { event Action&lt;T&gt; OnSomeEvent; } } </code></pre> <p>and its implementation.</p> <pre><code>// implicit interface implementation public class Foo3&lt;T&gt; : IGenericBar&lt;T&gt; { private Action&lt;T&gt; foo; event Action&lt;T&gt; IGenericBar&lt;T&gt;.OnSomeEvent { add { foo += value; } remove { foo -= value; } } } </code></pre> <p>for some reason we can build (as it should) and run:</p> <pre><code>/** does build **/ IGenericBar&lt;dynamic&gt; f = new Foo3&lt;dynamic&gt;(); f.OnSomeEvent += new Action&lt;dynamic&gt;(f_OnSomeEvent); </code></pre> <p>seems that the Type Parameter <em>does something extra</em> that the compiler is happy with.</p> <p>I am not sure what is going on, so I would like to know as well.</p> <p><strong>assumption, highly hypothetical (perhaps crap)</strong></p> <blockquote> <p>but currently I put my two cents on the comparison of types there must be made via the add/remove accessors in the linked list that holds the target/methods of the event. </p> <p>I bet that the compiler falls over the problem that it cannot guarantee what dynamic is in the external assembly, thus cannot determine if an element is already in the list or not, which is necessary to add or remove them.(Hence explicit interface implementation)</p> <p>We all know it is just some of a attributed object but it still seems that it needs an extra step where some strong-type is guaranteed, and that is what T does, at compile time.</p> </blockquote> <p><strong>/ assumption, highly hypothetical (perhaps crap)</strong></p>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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