title: Decorator with generic base class
body: <p>A co-worker of mine asked me last week if it were possible in C# to extend a generic class from its generic parameter.  He said it was possible in C++.
  What he wanted makes actually sense. He wanted a generic decorator to annotate an arbitrary class with additional information. Something like:</p>
  
  <pre><code>public class Decorator&lt;T&gt; : T
  {
      public object AdditionalInformation {get:set;}
  }
  </code></pre>
  
  <p>So that he can now use this generic decorator everywhere instead of T.</p>
  
  <p>The most similar thing I could come with was a container class with the original object, the additional information and an implicit conversion.</p>
  
  <pre><code>public class Decorator&lt;T&gt;
  {
      private readonly T _instance;
  
      public Decorator(T instance)
      {
          _instance = instance;
      }
  
      public T Instance
      {
          get { return _instance; }
      }
      public object AdditionalInformation { get; set; }
  
      public static implicit operator T(Decorator&lt;T&gt; deco)
      {
          return deco._instance;
      }
  }
  </code></pre>
  
  <p>But this is not the same because the implicit conversion is only one way. He cannot use it, for example, as a return type of a method because the additional information would be lost after he implicit conversion.</p>
  
  <p>Does anybody have a better idea?</p>