title: C# generic method with one parameter of multiple types
body: <p>I'm having a problem writing a generic method to retrieve AD Groups or Users with a parameter that can be one of two types - either <code>System.DirectoryServices.AccountManagement GroupPrincipal</code> or <code>UserPrincipal</code></p>
  
  <p>The method is as follows:-</p>
  
  <pre><code>private static IEnumerable&lt;string&gt; GetGroupsOrUsers&lt;T&gt;(T GroupOrUserPrincipal)
  {
     PrincipalSearcher ps = new PrincipalSearcher();
     ps.QueryFilter = GroupOrUserPrincipal;
  
     etc.........
  }
  </code></pre>
  
  <p>The problem is the GroupOrUserPrincipal is showing the following error:-</p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'T' to
    System.DirectoryServices.AccountManagement.Principal</p>
  </blockquote>
  
  <p>Am I able to do this or am I missing something ?</p>