简体   繁体   中英

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#)?

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 ! 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 .

The next step would be looking for other resources on the internet and a quick search located this question on SO:

How to create a method at runtime using 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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