title: Get an element from List<T> based on ID
body: <p>This question is related to this question:  <a href="https://stackoverflow.com/questions/4127917/given-system-type-t-deserialize-listt">Given System.Type T, Deserialize List&lt;T&gt;</a></p>
  
  <p>Given this function to retrieve a list of all elements...</p>
  
  <pre><code> public static List&lt;T&gt; GetAllItems&lt;T&gt;()
   {
      XmlSerializer deSerializer = new XmlSerializer(typeof(List&lt;T&gt;));
      TextReader tr = new StreamReader(GetPathBasedOnType(typeof(T)));
      List&lt;T&gt; items = (List&lt;T&gt;)deSerializer.Deserialize(tr);
      tr.Close();
   }
  </code></pre>
  
  <p>...I want to create a function to retrieve just one item of those with the needed UID (Unique ID):</p>
  
  <pre><code>public static System.Object GetItemByID(System.Type T, int UID)
  {
  
      IList mainList = GetAllItems&lt;typeof(T)&gt;();
      System.Object item = null;
  
      if (T == typeof(Article))
          item = ((List&lt;Article&gt;)mainList).Find(
              delegate(Article vr) { return vr.UID == UID; });
      else if (T == typeof(User))
          item = ((List&lt;User&gt;)mainList).Find(
              delegate(User ur) { return ur.UID == UID; });
  
      return item;
  }
  </code></pre>
  
  <p>However, this does not work since <code>GetAllItems&lt;typeof(T)&gt;();</code> call is not properly formed.</p>
  
  <p><strong>Question 1a</strong>: How can I fix the second function to properly return a unique element, given that all classes that will call GetItemByID() have UID as an element in them?  I'd love to be able to do  <code>public static &lt;T&gt; GetItemByID&lt;T&gt;(int UID)</code> if possible.</p>
  
  <p><strong>Question 1b</strong>: Same question, but suppose I cannot modify the function prototype of GetItemByID?</p>