title: How to pass a class to a method where the methods parameter is a generic
body: <p>This method below has been written 12 different times in my project using a different interface</p>
  
  <pre><code>ChannelFactory&lt;interface&gt;
  </code></pre>
  
  <p>and a different "User". </p>
  
  <pre><code>var user = new SomeWebServiceReference.User();
  </code></pre>
  
  <p>Examples below.</p>
  
  <p>So I'd like to make a single generic like class or a generic method in a class (not sure what I need) that passes in the "WebServiceAWI" interface and any of the other interfaces (ex. WebServiceBW, WebServiceAWA) and a "User" but I'm not sure how to do it.</p>
  
  <pre><code>    // file 1
      public void TestSomething(string url)
      { 
          BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
          EndpointAddress endpoint = new EndpointAddress(url);
  
          var channelFactory = new ChannelFactory&lt;WebServiceAWI&gt;(binding, endpoint);
  
          var webservice = channelFactory.CreateChannel();
  
          var user = new User(); // from ServiceReferenceARM 
          user.UserName = webservice.EncryptValue("someone");
          user.Password = webservice.EncryptValue("password");
  
          WebServiceResult result = webservice.AttorneysGet(user);
      }
  
      // file 2
      public void TestSomething(string url)
      { 
          BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
          EndpointAddress endpoint = new EndpointAddress(url);
  
          var channelFactory = new ChannelFactory&lt;WebServiceBW&gt;(binding, endpoint);
  
          var webservice = channelFactory.CreateChannel();
  
          var user = new User(); // from ServiceReferenceBW
          user.UserName = webservice.EncryptValue("someone");
          user.Password = webservice.EncryptValue("password");
  
          WebServiceResult result = webservice.AttorneysGet(user);
      }
  </code></pre>
  
  <p>I think I'm on the right track with the interface, but I'm not sure how to pass in a class that then acts like a generic.</p>
  
  <p>Here is what I have so far.</p>
  
  <p>Calling it like this</p>
  
  <pre><code>TestTOSomething&lt;WebServiceAWI, WebServicesTO.ServiceReferenceARM.User&gt;(new ServiceReferenceARM.User(), url);
  </code></pre>
  
  <p>and then implementing it like this but I know this is wrong.</p>
  
  <pre><code>    public void TestTOSomething&lt;T, K&gt;(K newUser, string url)
      {
  
          BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
          EndpointAddress endpoint = new EndpointAddress(url);
  
          var channelFactory = new ChannelFactory&lt;T&gt;(binding, endpoint);
  
          var webservice = channelFactory.CreateChannel();
  
          var user = newUser;
          user.UserName = webservice.EncryptValue("someone");
          user.Password = webservice.EncryptValue("password");
  
          WebServiceResult result = webservice.AttorneysGet(user);
      }
  </code></pre>