我希望使用的是从外边传过来的类型tt来调用test1范型方法
class Program
{
static void Main(string[] args)
{
MyClass m = new MyClass();
m.tt = typeof(Program);
m.test2();
}
}
[Serializable]
class MyClass
{
public Type tt { get; set; }
public int userid { get; set; }
public string Name { get; set; }
public string test2()
{
// test1<T>();
我希望使用的是从外边传过来的类型tt来调用test1范型方法
}
public string test1<T>()
{
return typeof(T).ToString();
}
}
class Program
{
static void Main(string[] args)
{
MyClass m = new MyClass();
m.tt = typeof(Program);
m.test2();
}
}
[Serializable]
class MyClass
{
public Type tt { get; set; }
public int userid { get; set; }
public string Name { get; set; }
public string test2()
{
// test1<T>();
我希望使用的是从外边传过来的类型tt来调用test1范型方法
}
public string test1<T>()
{
return typeof(T).ToString();
}
}
{
static void Main(string[] args)
{
MyClass m = new MyClass();
m.tt = typeof(Program);
string s = m.test2();
Console.WriteLine(s);
}
}
[Serializable]
class MyClass
{
public Type tt; public string test2()
{
return test1(tt);
} public string test1 <T>(T x)
{
return x.GetType().ToString();
}
}
{
static void Main(string[] args)
{
MyClass m = new MyClass();
m.tt = typeof(Program);
string s = m.test2();
Console.WriteLine(s);
}
} [Serializable]
class MyClass
{
public Type tt; public string test2()
{
return test1(tt);
} public string test1 <T>(T x)
{
return x.ToString();
}
}
MyClass instance = ...
Type genericParameter = ...
object[] parameters = ...
object result = typeof(MyClass).GetMethod("test1").MakeGenericMethod(genericParameter).Invoke(instance, parameters);