Método genérico ejecutado con un tipo de tiempo de ejecución [duplicado]
Esta pregunta ya tiene una respuesta aquí:
¿Cómo uso la reflexión para llamar a un método genérico? 7 respuestasTengo el siguiente código:
public class ClassExample
{
void DoSomthing<T>(string name, T value)
{
SendToDatabase(name, value);
}
public class ParameterType
{
public readonly string Name;
public readonly Type DisplayType;
public readonly string Value;
public ParameterType(string name, Type type, string value)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException("name");
if (type == null)
throw new ArgumentNullException("type");
this.Name = name;
this.DisplayType = type;
this.Value = value;
}
}
public void GetTypes()
{
List<ParameterType> l = report.GetParameterTypes();
foreach (ParameterType p in l)
{
DoSomthing<p.DisplayType>(p.Name, (p.DisplayType)p.Value);
}
}
}
Ahora, sé que no puedo realizar DoSomething () ¿hay alguna otra forma de usar esta función?