I want to write a code generator and save these codes with mvp pattern, can I use Reflection.Emit as a solution or CodeDom is better?
EDIT————–
I have to do 2 work, firstly I want to compile this code at runtime and run it and secondly generate the source code as an option.
Although you can achieve some aspects of your question with both Namespaces (System.CodeDom and System.Reflection.Emit) you can’t mix the two different concepts and use the option(s) that better fits whatever you want to do.
If you just want to generate and compile C#\VB code maybe you want do use System.CodeDom:
Check this small example on how to define a method through CodeDom:
As for the System.Reflection.Emit its used to generate and manipulate MSIL (Microsoft Intermediate Language) which is lowest-level human-readable programming language defined by the Common Language Infrastructure specification and used by the .NET Framework. Note that MSIL is now known as CIL (Common Intermediate Language):
The use of this approach leads you to learn CIL bytecode instructions which is a rather difficult and complex task even if you’re familiar with assembly code and might not be ideal if what you want is rather simple and fast to implement. Check wikipedia article on CIL and CIL instructions list for a first impression.