title: Passing a generic List<T> as a delegate parameter
body: <p>I wrote an event which is supposed to pass a List with generic items of type (T) to all subscribers:</p>
  <pre><code>public delegate void GenericListItemCountChangedEvent(List&lt;Object&gt; sender, GenericListItemCountChangedEventArgs e);
  public event GenericListItemCountChangedEvent GenericListItemCountChanged;
  
  private void RaiseGenericListItemCountChanged&lt;T&gt;(List&lt;T&gt; List) where T : BaseElem {
      if (GenericListItemCountChanged != null)
          GenericListItemCountChanged(List as List&lt;Object&gt;, new GenericListItemCountChangedEventArgs(typeof(T)));
  }
  </code></pre>
  <p>This is a statement from a class, which subscribes to the event above:</p>
  <pre><code> _catalog.GenericListItemCountChanged += (sender, e) =&gt; GenericListItemCountChanged(sender, e);
  </code></pre>
  <p>And this is the method the event is forwarded to inside the subscriber:</p>
  <pre><code>private void GenericListItemCountChanged(List&lt;Object&gt; sender, Catalog.GenericListItemCountChangedEventArgs e) {
      Catalog.ListTypes changedListType = Catalog.GetListTypeFromList(changedList); 
      //GetListTypeFromList expects parameter to be a type of &lt;T&gt; where T : BaseElem
  }
  </code></pre>
  <p>Obviously, a <code>List&lt;Object&gt;</code> cannot be converted to a <code>List&lt;T&gt; where T : BaseElem</code>.</p>
  <p>I'll accept your answer if you could provide a solution for retrieving the List with items of their &quot;real&quot; type inside the method, which handles the event.<br />
  (Restoring original List state)</p>
  <p>The &quot;real&quot; type of the items inside the list is stored inside the EventArgs.<br />
  But I don't know if that could help me...</p>
  <p><strong>SOLUTION:</strong><br />
  I could not have figured this out without the help of @ChrFin, thanks mate!</p>
  <p><em>public class Catalog : Object</em></p>
  <pre><code>public delegate void GenericListItemCountChangedEvent(IEnumerable&lt;BaseElem&gt; sender, GenericListItemCountChangedEventArgs e);
  public event GenericListItemCountChangedEvent GenericListItemCountChanged;
  
  private void RaiseGenericListItemCountChangedEvent&lt;T&gt;(List&lt;T&gt; List) where T : BaseElem {
      if (GenericListItemCountChanged != null) {
          GenericListItemCountChanged(List, new GenericListItemCountChangedEventArgs());
      }
  }
  public void ForceRaiseGenericListItemCountChangedEvent&lt;T&gt;(List&lt;T&gt; List) where T : BaseElem {
      RaiseGenericListItemCountChangedEvent(List);
  }
  
  public class GenericListItemCountChangedEventArgs {
      public GenericListItemCountChangedEventArgs() {
      }
  }
  </code></pre>
  <ul>
  <li></li>
  </ul>
  <pre><code>    public static ListTypes GetListTypeFromList&lt;T&gt;(IEnumerable&lt;T&gt; List) where T : BaseElem {
          Type typeofT = List.GetType().GetGenericArguments()[0];
          //typeofT now contains correct subtype of 'BaseElem'
          return ListTypes.SomeType //based on 'typeOfT'
      }
  </code></pre>
  <p><em>public partial class MainWindow : Window</em></p>
  <pre><code>    _catalog.GenericListItemCountChanged += (sender, e) =&gt; GenericListItemCountChanged(sender, e);
  </code></pre>
  <ul>
  <li></li>
  </ul>
  <pre><code>private void GenericListItemCountChanged(IEnumerable&lt;BaseElem&gt; sender, Catalog.GenericListItemCountChangedEventArgs e) {
              Catalog.ListTypes changedListType = Catalog.GetListTypeFromList(sender);
              //We now know the changed ListType
  }
  </code></pre>
  <p>Thank you very much!</p>