title: Property of generic type in non-generic class
body: <p><strong>Intro</strong></p>
  
  <p>I'm working with the legacy code which contains two classes:</p>
  
  <ul>
  <li>I have a class which stores its value of <code>System.Object</code> type.
  (I named this class as <code>DomainItem</code>) 
  <ul>
  <li>Its Identifier property refers to
  enum which holds information what a type of <code>DomainItem</code> is (in the
  context of business domain).</li>
  </ul></li>
  <li>There is also a class which stores these
  items as an Enumerable List. (<code>DomainItems</code>)</li>
  </ul>
  
  <p>What's more:</p>
  
  <ul>
  <li>I don't want to change these classes into generic. This code is very sensitive and not covered by tests.</li>
  <li>In order to get <code>DomainItem</code>, I must get it from <code>DomainItems.Items</code> collection.</li>
  </ul>
  
  <p><strong>Code</strong></p>
  
  <p>The code for classes is equivalent as below:</p>
  
  <pre><code>public class DomainItem
  {
      public Identifier Identifier { get; set; } // Readonly in the "real" code
      public object Value { get; set; }
  }
  
  public class DomainItems
  {
      public IEnumerable&lt;DomainItem&gt; Items { get; set; }
  }
  </code></pre>
  
  <p><strong>The question is</strong></p>
  
  <p>How can I extend these classes using generics, to resolve type of Value property in the compile time. Is it even possible?</p>
  
  <p><strong>Example case</strong> might be as following:</p>
  
  <pre><code>DomainItem price = new DomainItem { Value = 25.20d, Identifier = Identifier.Price };
  // ....
  double priceValue = price.ProperValue; // generic property of type T
  </code></pre>
  
  <p>Obviously, above code is conceptual and it shows what I want to achieve. Any suggestions how to resolve that? Is it even possible?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>My idea is to create a new <code>IEnumerable&lt;DomainItem&lt;T&gt;&gt;</code> where the collection is populated from non-generic <code>DomainItem</code> objects. Since the type of <code>DomainItem.Value</code> is known, it should be possible to make such collection somehow.</p>