title: Creating generic method and using type parameter
body: <p>I have created this method which is an object factory:</p>
  
  <pre><code>public static T GetService&lt;T&gt;(T serviceInterface)
  {
      if (serviceInterface.Equals(typeof(IMemberService)))
      {
          return (T)(object)new MemberService();
      }
      else if (serviceInterface.Equals(typeof(ILookupService)))
      {
          return (T)(object)new LookupService();
      }
      throw new ArgumentOutOfRangeException("No action is defined for service interface " + serviceInterface.Name);
  }
  </code></pre>
  
  <p>Now, I would like to go further and eliminate the need for "serviceInterface" parameter, but my problem is - I don't know how to compare type parameter T to an interface: doing</p>
  
  <pre><code>T.Equals(typeof(ILookupService)) 
  </code></pre>
  
  <p>gives compiler error: 'T' is a 'type parameter', which is not valid in the given context.</p>
  
  <p>Any ideas how could I compare a type parameter to an interface?</p>
  
  <p>Thank you,
  Andrey</p>