emit class with a property of the same type as declaring emitted type

a 夏天 提交于 2019-12-20 01:41:30

问题


I have found how to emit a class, like this:

class MyClass
{
    String MyProperty { get; set; }
}

Cannot figure out how to emit the following:

class MyClass
{
    MyClass MyProperty { get; set; }
}

The problem I faced is:

In order to emit the setter and getter, I need a variable representing the final compiled/emitted Type. In order to emit this Type, I need to emit setter/getter first. I guess it is possible, because the language allows that in static compilation.


回答1:


In order to emit the setter and getter, I need a variable representing the final compiled/emitted Type

Actually, you don't: you just need to pass the TypeBuilder as the type of the property (TypeBuilder inherits from Type, so it's a valid argument for the returnType parameter of DefineProperty)



来源:https://stackoverflow.com/questions/23620752/emit-class-with-a-property-of-the-same-type-as-declaring-emitted-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!