Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Every now and then I stumble upon an implementation issue, where I deeply regret that <code>C&lt;T&gt;</code> cannot inherit <code>T</code>. Unfortunately, I have never recorded these issues and so I can describe just the most recent one - the one I have stumbled upon right now. So here it is:</p> <p>Our system is extensible through metadata, which becomes available at run-time. The metadata is translated to a type dynamically generated at run-time using Reflection.Emit. Unfortunately, the dynamically generated type has to satisfy the following conditions:</p> <ol> <li>It must derive from some other type, provided as a parameter to the dynamic type creator. This type is called the <strong>ancestor type</strong> and is always a statically compiled type.</li> <li>It must implement several interfaces, say <code>IDynamicObject</code> (our interface), <code>System.ComponentModel.INotifyPropertyChanged</code> and <code>Csla.Core.IMobileObject</code>. Note, that this condition places certain constraints on the ancestor type. For instance, the ancestor type may not implement the <code>IDynamicObject</code> interface, except if all the interface methods are implemented abstractly. There are other constraints, all of which must be checked.</li> <li>It should (and it does) override the <code>object</code> methods <code>Equals</code>, <code>ToString</code> and <code>GetHashCode</code>.</li> </ol> <p>Currently, I had to use Reflection.Emit to emit all the IL code to satisfy these conditions. Of course, some tasks may be forwarded to statically compiled code. For instance, the override of the <code>object.Equals(object)</code> method invokes <code>DynamicObjectHelper(IDynamicObject, IDynamicObject)</code> which is a statically compiled C# code doing the largest bulk of the work of comparing two dynamic objects for equality. But this is more of an exception than the rule - most of the implementation is emitted, which is a pain in the butt.</p> <p>Would not it be great to be able to write a generic type, like <code>DynamicObjectBase&lt;T&gt;</code> which will be instantiated with the ancestor type and serve as the actual base type of the dynamically generated type? As I view it, the generic type <code>DynamicObjectBase&lt;T&gt;</code> could implement much of the dynamic type requirements in a statically compiled C# code. The dynamically emitted type would inherit it and probably, just override a few simple virtual methods.</p> <p><strong>To conclude, my compelling reason is that letting <code>C&lt;T&gt;</code> inherit from <code>T</code> would greatly simplify the task of emitting dynamic types.</strong></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.
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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