Ho una classeImpostazione tipo generico in fase di esecuzione
public class A<T>
{
public static string B(T obj)
{
return TransformThisObjectToAString(obj);
}
}
L'uso di stringa sopra è puramente esemplare. Posso chiamare la funzione statica come questo bene su un noto tipo/specificato:
string s= A<KnownType>.B(objectOfKnownType);
Come faccio a fare questa chiamata, se non so T in anticipo, piuttosto ho una variabile di tipo Digitare che contiene il tipo. Se faccio questo:
Type t= typeof(string);
string s= A<t>.B(someStringObject);
ottengo questo errore di compilazione:
Cannot implicitly convert type 't' to 'object'
chiudere [c-sharp-dinamico generico tipo] (http://stackoverflow.com/questions/2078914/c-sharp- dynamic-generic-type) – nawfal