我正在基于我收到的JSON使用System.Reflection.Emits
在运行时创建动态类,如下所示。
我正在创建的动态类也可以具有List< Property_2 >
或Property_3
的属性类型。
现在,我能够在运行时首次尝试创建动态类,但是问题是我无法处理动态创建的类的实例。
我尝试了一个using
块,但由于它没有实现IDisposable
,这给了我编译时错误。
您能否建议我如何处置动态创建的实例 上课?
输入:(Json)
{
"Class_1": {
"Property_1": 0,
"Property_2": [
{
"Property_2_1": 0,
"Property_2_2": "Hello"
}
],
"Property_3": {
"property_3_1": 0,
"Property_3_2": "Hello"
}
}
}
输出
class Class_1
{
public int Property_1 {get; set;}
public List<Property_2> Property_2 {get; set;}
public Property_3 Property_3 {get; set;}
}
class Property_2
{
public int Property_2_1 {get; set;}
public string Property_2_2 {get; set;}
}
class Property_3
{
public int property_3_1{get; set;}
public string Property_3_2{get; set;}
}