Questions tagged [codedom]

CodeDOM is a framework which can be used to create an (abstract) expression tree representing real code structures (for example, classes, statements, etc.) in a language-independent way. This means if you construct an expression tree, you can use (or write) code generators to output the same logical structure in multiple different target languages. Language generators exist for VB.NET, C#, and JScript, but you can also create your own.

What is CodeDOM?

CodeDOM is a .NET library from Microsoft which:

  • Gives you a way to represent source code as expression objects

  • Provides some pre-built generators to translate the expressions into raw source code

  • Makes it easy to compile the generated source to executable code

Here is an excerpt from MSDN describing CodeDOM:

The CodeDOM provides types that represent many common types of source code elements. You can design a program that builds a source code model using CodeDOM elements to assemble an object graph. This object graph can be rendered as source code using a CodeDOM code generator for a supported programming language. The CodeDOM can also be used to compile source code into a binary assembly.

Some common uses for the CodeDOM include:

  • Templated code generation: generating code for ASP.NET, XML Web services client proxies, code wizards, designers, or other code-emitting mechanisms.

  • Dynamic compilation: supporting code compilation in single or multiple languages.

If you look into CodeDOM you will probably encounter a lot about abstract syntax trees (ASTs). This is the technical term for an expression tree in this context (originating from the way code generators, parsers, and compilers are written). If you plan to get into CodeDOM it helps to understand the basic concept; Wikipedia has a reasonable article on the subject.

What type of question should use this tag?

Questions should use this tag if they relate to the use, comprehension, or interaction with the CodeDOM library. It could also be used on questions relating to generation of code using a document object model (DOM) strategy similar to that provided by the Microsoft CodeDOM library.

Further Reading

593 questions
0
votes
1 answer

How to cast a CodeDOM object into its correct type

I have some code that generates an array of tuples of CodeCompileUnit and CodeTypeDeclarations of different classes. After I generate the array I want to be able to invoke and create an instance of a given member of the array. However, can't seem…
ElfsЯUs
  • 1,188
  • 4
  • 14
  • 34
0
votes
1 answer

CodeDom.compiler memory

I am generating assembly on runtime . Problem is that i cant get rid-of it after i am done with it. I need to destroy this assambly what i have created string _Errors = ""; object[] parms = null; CodeDomProvider…
Woland
  • 1,050
  • 3
  • 19
  • 36
0
votes
1 answer

Using CodeDOM to source code and class file togther

i have created a form for a codeDOM compiler and it can compile my code if its in a single text file but i want to be able to compile the source code in the text file and a class thats in a text file so they can work together. I am unsure how to…
Chris Devine
  • 3,859
  • 2
  • 13
  • 7
0
votes
1 answer

How to test a BuildProvider

I have created a simple BuildProvider as a starting point, and althogh I get no errors, I don't have access to the generated class either. In fact, i don't know if my BuildProvider was even invoked. Is there a way to debug a BuildProvider? How do I…
Michiel van Oosterhout
  • 22,839
  • 15
  • 90
  • 132
0
votes
1 answer

Adding resources and setting Exe description

I am generating C# code at runtime and compiling it with the CSharpCodeProvider The two problems I'm having are How to add resources to the generated exe? How to set the executable description (i.e company name and others) to it? Thanks.
Sri Harsha Chilakapati
  • 11,744
  • 6
  • 50
  • 91
0
votes
0 answers

Is it possible to inject a class into the executing assembly at runtime?

I am experimenting with the CSharpCodeProvider .NET Code DOM class an I am able to compile an assembly and create an instance defined within the assembly, but I'm interested to know whether it is possible to 'inject' code or rather a class into a…
Drew R
  • 2,988
  • 3
  • 19
  • 27
0
votes
1 answer

CodeDOM for creating classes from existing entity class

I used CodeDOM to generate a class (entity class) from a given database table. I used this tutorial and made my application. It's OK and working fine. By using codeDOM can I edit an existing entity class and regenerate it against the table it's…
Irshad
  • 3,071
  • 5
  • 30
  • 51
0
votes
1 answer

How do I generate a constructor and the code within?

I'm using System.CodeDom to generate code. Can someone please tell me how I would create the code within a constructor. The output that I want: internal class CurrencyMap : EntityTypeConfiguration { public CurrencyMap() …
Matt
  • 6,787
  • 11
  • 65
  • 112
0
votes
2 answers

How to create a private class using CodeDOM?

I am using CodeDOM to compile a *.cs file based on the data table retrieve form SQL server. So, the compiled code should be the entity class of the particular table. I managed to compile the class as public, internal or interface classes. Ex.…
Irshad
  • 3,071
  • 5
  • 30
  • 51
0
votes
1 answer

System.CodeDom.CodeCompileUnit from System.Reflection.Emit.AssemblyBuilder instance

I'm looking at CodePlex code for TLBImp2 and want to generate C# source code from the IL emitted. Is there a way to get a System.CodeDom.CodeCompileUnit from a System.Reflection.Emit.AssemblyBuilder instance?
Roger
0
votes
1 answer

How to remove @prefix from field type when generating code with CSharpCodeProvider

I create field member like this: var fieldMember = new CodeMemberField("int", "Test"); Now because field type is "int" which is reserved C# keyword generated code looks like this: @int Test; Which does not compile.
nefarel
  • 596
  • 4
  • 10
0
votes
1 answer

Can I compile Multiple classes into one program with CodeDom?

Now this has been bugging me for ages and it's time to find out if it's possible. I currently have a working CodeDom that can compile one class, but I have created a program with multiple classes that I want to compile with CodeDom. I've tried…
Daaksin
  • 834
  • 3
  • 13
  • 28
0
votes
2 answers

transporting byte array to codedom giving me an error

hey guys im working on a project where i have to generate an executable containing the byte array of another executable, basicly my program loads a executable and stores all of the corresponding bytes in an array and then i give codedom the source…
Paze
  • 49
  • 7
0
votes
1 answer

How do I expose member objects via using CodeDOM?

Everywhere I see tutorials on how to compile assemblies using the System.CodeDom namespace. But how can I access a member object of an assembly from a runtime compiled assembly (I'm not talking about accessing a class, I want to access a specific…
Attila Kun
  • 2,215
  • 2
  • 23
  • 33
0
votes
0 answers

CodeDom to Serialize object to source code

I'm making a converter from SSRS to Telerik Reporting and then using reflection to write out the source code of the .Designer.cs file. I'm reading the CodeDom attributes with Reflection to control the output, but is there any way to invoke CodeDom…
Steve
  • 1,995
  • 2
  • 16
  • 25