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