Is there a way to build a new type during Runtime?

前端 未结 4 1125
[愿得一人]
[愿得一人] 2020-12-28 15:47

I am going to ask a question that might sound weird.

Is there a way to build a new class during Runtime? Or at least, add a new property to an existing class.

<
4条回答
  •  长情又很酷
    2020-12-28 16:17

    You might take a look at the System.CodeDom namespace. According to one of the pages linked from there:

    The .NET Framework includes a mechanism called the Code Document Object Model (CodeDOM) that enables developers of programs that emit source code to generate source code in multiple programming languages at run time, based on a single model that represents the code to render.

    I'm not at all an expert in this, I just remembered seeing it on my .NET Framework poster on my wall. :)

    Edit: Since writing this answer, I have played with System.CodeDom a bit. I've written a blog post that uses some basic CodeDom that may help those wanting to get started with it.

提交回复
热议问题