I have a class
public class A<T>
{
public static string B(T obj)
{
return TransformThisObjectToAString(obj);
}
}
The use of string above is purely exemplary. I can call the static function like this just fine on a known/specified type:
string s= A<KnownType>.B(objectOfKnownType);
How do I make this call, if I don't know T beforehand, rather I have a variable of type Type that holds the type. If I do this:
Type t= typeof(string);
string s= A<t>.B(someStringObject);
I get this compiler error:
Cannot implicitly convert type 't' to 'object'
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…