我在这里阅读了如何在 C# 中在运行时创建匿名类型
AssemblyBuilder dynamicAssembly =
AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("MyDynamicAssembly"),
AssemblyBuilderAccess.Run);
string propertyName = "prp_1";
//Type propertyType = new Type();
ModuleBuilder dynamicModule = dynamicAssembly.DefineDynamicModule("MyDynamicAssemblyModule");
TypeBuilder dynamicType = dynamicModule.DefineType("MyDynamicType", TypeAttributes.Public);
PropertyBuilder property =
dynamicType.DefineProperty(
propertyName,
System.Reflection.PropertyAttributes.None,
propertyType, // idk what to put here?
new[] { propertyType } // and here ?
);
//call this first
AddProperty(dynamicType, propertyName, propertyType );
//then we ' ll dynamic type
Type myType = dynamicType.CreateType();
被调用的函数
public static void AddProperty(TypeBuilder typeBuilder, string propertyName, Type propertyType)
代码中有propertyType,我不知道该放什么。我可以做吗
type mytype = \\typefree?
谢谢你。