简体   繁体   English

是否有可能编写在运行时生成类,方法,成员的代码?

[英]Is it possible writing code that generate a class, method, member at runtime ?

Is it possible writing code that generate a class, method, member at runtime using .NET (C#)? 是否有可能使用.NET(C#)编写在运行时生成类,方法,成员的代码?

For more details consider this scenario : 有关详细信息,请考虑以下情形

create a dynamic workflow program to enable user for creating his own process, activities, and writing dynamic SQL SPs, …, and collect all this stuff together then generate a classes , member variables , member functions , UIs , conditions , … dynamically at run-time ! 创建一个动态工作流程程序 ,使用户能够创建自己的进程,活动,编写动态SQL SP,...,并将所有这些东西收集在一起,然后生成一个 ,成员变量 ,成员函数UI条件 ......时间 ! in other word your own dynamic code factory framework ! 换句话说你自己的动态代码工厂框架

Yes, there are various options for this: 是的,有各种各样的选择:

Quick answer: Yes! 快速回答:是的!

For a detail of how to achieve this you would want to start your learning by looking at Reflection . 有关如何实现这一目标的详细信息,您可以通过查看Reflection来开始学习。

The next step would be looking for other resources on the internet and a quick search located this question on SO: 下一步是在互联网上寻找其他资源,并在SO上快速搜索这个问题:

How to create a method at runtime using Reflection.emit 如何使用Reflection.emit在运行时创建方法

Dynamic Language Runtime may also be worth a look. 动态语言运行时也值得一看。

The short response is yes. 简短的回答是肯定的。 You have to look and study the following technologies: 您必须查看和研究以下技术:

CodeDom CodeDom中

Windows Wordflow Foundation Windows Wordflow Foundation

If it is anyway useful can be discussed: One able to "dynamically" program a workflow in a so specific mode will probably prefer to write the code by hand himself. 如果无论如何有用可以讨论:能够以特定模式“动态”编程工作流程的人可能更愿意亲自编写代码。

Another alternative of using strong types in this case, you may consider also using 在这种情况下使用强类型的另一种方法,您也可以考虑使用
Dynamic object to allow fully featured dynamic behaviour. 动态对象允许全功能动态行为。

Could be more appropriate then strong typing generated at runtime, in this case. 这种情况下,可能比在运行时生成的强类型更合适。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM