3
使用类型生成器我很好地动态创建一个类型。是否有可能从匿名类型做到这一点?从一个匿名对象动态创建一个对象
我到目前为止;
//CreateType generates a type (so that I can set it's properties once instantiated) from an //anonymous object. I am not interested in the initial value of the properties, just the Type.
Type t = CreateType(new {Name = "Ben", Age = 23});
var myObject = Activator.CreateInstance(t);
现在是否可以使用类型“t”作为类型参数?
我的方法:
public static void DoSomething<T>() where T : new()
{
}
我想打电话给使用动态创建的“T”型这种方法。所以我可以打电话;
DoSomething<t>(); //This won't work obviously
你的意思是你构建一个匿名类型的对象,并希望得到它的类型,以创造更多的人? – Botz3000 2013-03-08 09:50:21