Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View source code for CodeDom

Tags:

c#

codedom

Is there some way to get the source code files from the executable I generated using CodeDom? I would like to be able to open the source files so that I can clearly see where I made errors generating any code.


1 Answers

If you generate an executable with CodeDom, you can also generate its source code from it. The example below shows how to create a source file from the CodeCompileUnit object.

CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");
System.CodeDom.Compiler.CodeGeneratorOptions options = new CodeGeneratorOptions();
options.BracingStyle = "C";
using (StreamWriter sw = File.CreateText(@"c:\temp\MyFile.cs"))
{
    provider.GenerateCodeFromCompileUnit(unit, sw, options);
}
like image 92
carlosfigueira Avatar answered Sep 17 '25 07:09

carlosfigueira