using System;
using System.Reflection;
using System.Collections.Generic;
namespace ConsoleTest
{
class Program
{
static void Main(string[] args)
{
Assembly asm = Assembly.GetExecutingAssembly();
string pair1 = "ConsoleTest.Pair";
string pair2="ConsoleTest.Pair`2";
Type type= asm.GetType(pair2,true);
type = type.MakeGenericType(typeof(int), typeof(string));
//Console.WriteLine(type.IsGenericType);
ConstructorInfo ctor = type.GetConstructor(new Type[] { typeof(int), typeof(string) });
object obj = ctor.Invoke(new object[] { 1, "wth" });
Console.ReadLine();
}
}
public class Pair<T, S> {
public T first;
public S second;
public Pair(T first, S second) {
this.first = first; this.second = second;
}
}
public class Pair {
public object first;
public object second;
public Pair(object first, object second)
{
this.first = first; this.second = second;
}
}
}
泛型反射
最新推荐文章于 2024-07-16 02:08:53 发布