title: Creating an instance of a class that implements generic interface
body: <p>Ok I have a generic interface</p>
  
  <pre><code>public IConfigurationValidator&lt;T&gt;
  {
   void Validate();
  }
  </code></pre>
  
  <p>a class that implements it:</p>
  
  <pre><code>public class SMTPServerValidator : IConfigurationValidator&lt;string&gt;
      {
  
  
          public void Validate(string value)
          {
              if (string.IsNullOrEmpty(value))
              {
                  throw new Exception("Value cannot be null or empty");
              }
          }
  
  
      }
  </code></pre>
  
  <p>I now want to use reflection to create an instance of SMTPServerValidator, because I know the AssemblyQualifiedName of the type.</p>
  
  <p>I was thinking to use Activator.CreateInstance and cast that to the interface...
  like this:</p>
  
  <pre><code>IConfigurationValidator&lt;T&gt; validator = (IConfigurationValidator&lt;T&gt;)Activator.CreateInstance(typeof(SMTPServerValidator));
  </code></pre>
  
  <p>I dont know what T is....how do I use reflection to create an instance of this class?</p>
  
  <p>There is another class that has that I am dealing with that I left out:</p>
  
  <pre><code>public class ConfigurationSetting&lt;T&gt;
      {
  
          IConfigurationValidator&lt;T&gt; m_Validator;
  
          public ConfigurationSetting(IConfigurationValidator&lt;T&gt; validator)
          {
              m_Validator = validator;
          }
  
          public void Validate(T value)
          {
              m_Validator.Validate(value);
          }
      }
  </code></pre>
  
  <p>In the end I am trying to create ConfigurationSettings and need to pass in the appropriate validator based on the parameter.</p>