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
4
votes
3 answers

What is the most interesting and promising approach to implement a compiler in C#?

I am just in the beginning of my graduation project that is supposed to last for 6 months. The goal of the project is to implement a .Net-compiler for one scripting language. I had the Compiler Construction as a subject in my curriculum and am…
Alexander Galkin
  • 12,086
  • 12
  • 63
  • 115
4
votes
3 answers

Want to use COM dll file on deployed machines without registering dll files

I will make this very simple, as it can get quite confusing very quickly. I have a COM dll (made in VB6) that I would like to be able to use through my C# application. Below are the steps I have taken, and the results. Created COM dll through…
user725913
4
votes
1 answer

C# CodeDom Double Type Reference

I am able to make a call to some type by using CodeMethodInvokeExpression along with CodeTypeReferenceExpression, but I would like to be able to make a reference to the following line of code: Process p = new Process(); p.StartInfo.FileName =…
user725913
4
votes
1 answer

View source code for 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.
user725913
4
votes
2 answers

Prevent CodeDom from splitting large strings

I am using CodeDom to generate C# code, and part of that involves to spitting out String variable contents. Sometimes, these strings can get to be quite long. Is there a way to prevent the CodeDom code generator from splitting those large strings…
Satyajit
  • 523
  • 4
  • 17
4
votes
4 answers

C# - Code compiler for .NET & CF.NET

I've a same project that need to be compiled with .NET and Compact .NET Framework. It is possible to create a C# compiler that will compile my project with both framework ? Some feature aren't present in CF.NET Framework so I created it by myself…
Arnaud F.
  • 8,252
  • 11
  • 53
  • 102
4
votes
5 answers

T4 vs CodeDom vs Oslo

In an application scaffolding project on which I'm working, I'm trying to decide whether to use Oslo, T4 or CodeDom for generating code. Our goals are to keep dependencies to a minimum and drive code generation for a domain driven design from user…
user29439
4
votes
0 answers

How create Type at Runtime and unload symbols after usage

The Problem I need create type dynamicly (without dynamic or ExpandoObject), I need of Type to get strong type on return of my query (making dynamicly too). I have tried use Reflection.Emit and CodeDOM, but both keep the symbols created on…
Renatto Machado
  • 1,534
  • 2
  • 16
  • 33
4
votes
2 answers

CodeDomProvider.CompileAssemblyFromSource - Can't Find Roslyn (csc.exe)

We recently upgraded from an old CodeDomProvider to the new Roslyn CodeDomProvider called Microsoft.CodeDom.Providers.DotNetCompilerPlatform. It works fine, but it looks for the csc.exe in the wrong place. The NuGet package puts the exe in the…
Christian Findlay
  • 6,770
  • 5
  • 51
  • 103
4
votes
1 answer

Roslyn - CodeDom: HowTo dynamically compile Code to Universal-Windows-Library

I am generating a .NET Dll dynamically containing wrapper classes for a WPF Project. I am doing it with the System.CodeDom.Compiler.CodeDomProvider class. Now I have to create a wrapper class for a Universal-Windows-Dll. Since the…
michlG
  • 55
  • 1
  • 5
4
votes
3 answers

Is any simple way to create method and set its body dynamically in C#?

I hold body of method in string. I want to create method dynamically. But I don't know, how to set its body. I saw very tedious way using CodeDom. And I saw using Emit with OpCodes. Is any way to use ready code from string variable? string…
greatromul
  • 1,069
  • 2
  • 15
  • 42
4
votes
3 answers

Using .NET CodeDOM to declare and initialize a field in one statement

I want to use CodeDOM to both declare and initialize my static field in one statement. How can I do this? // for example public static int MyField = 5; I can seem to figure out how to declare a static field, and I can set its value later, but I…
Chris Farmer
  • 24,974
  • 34
  • 121
  • 164
4
votes
1 answer

Generate CodeDOM from existing class

I need to add a class (Type) to the CodeNamespace. I have a C# class already written but I don't want to convert it manually to CodeDOM. Is there a way to load an existing into a CodeTypeDeclaration. It can be runtime or pre-build process.
jsgoupil
  • 3,788
  • 3
  • 38
  • 53
4
votes
1 answer

Where is System.CodeDom.Compiler.CompilerParameters in Silverlight?

I want to create Mathematics Expression Evaluator in Silverlight. To do that easily, I need compilation on the fly using System.Reflection, System.Reflection.Emit, System.CodeDom.Compiler, and other related assemblies. However, I cannot find this…
4
votes
2 answers

Is it possible to call C# lexical/syntactic analyzers without compilation?

Considering this question of SO, where whole C# in-memory compiler is being called. When only lexical and syntactic analyzing is required: parse text as a stream of lexemes, check them and exit. Is it possible in current version of…
abatishchev
  • 98,240
  • 88
  • 296
  • 433