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
2 answers

Are there differences between EnvDTE or CodeDom when generating Code

I have the requirement to generate and read some CS classes with a DSL, I have adopted one method for reading the CS files using EnvDTE and my colleague has used CodeDom to produce the CS files. Is it just sugar or is there a big difference…
Phill Duffy
  • 2,805
  • 3
  • 33
  • 45
0
votes
1 answer

Interacting with assembly generated by CSharpCodeProvider

I made a toy compiler for learning/experimentation. Here's the code for compiling some C# code: using System; using System.CodeDom.Compiler; using System.Reflection; using Microsoft.CSharp; namespace ProgrammingSystem { public class Compiler …
Aaron Anodide
  • 16,906
  • 15
  • 62
  • 121
0
votes
2 answers

Building Dictionaries with CodeDom

I'm trying to figure out a way to build something like this using CodeDom public System.Collections.Generic.Dictionary Attributes { get { return new System.Collections.Generic.Dictionary() { …
Eric Herlitz
  • 25,354
  • 27
  • 113
  • 157
0
votes
1 answer

Codedom at runtime

I am building a code generation tool using vs 2010 visualisation & modelling sdk. One of the things that I need to generate is a simple data capture ui (windows forms, preferably using devexpress layout control), with capture fields & labels for…
0
votes
1 answer

Less Strict CodeDomProvider for Compiling DLLs

Is there a way to have a less-strict compilation with a CodeDomProvider? I am trying to compile and load dll files into my already running program by using: public static String Compile(string commandName, string source = "") { private…
Mike S
  • 97
  • 1
  • 8
0
votes
1 answer

codedom add reference

I want make a mail sender generator . but I have problem with codedom reference . my result is : "The type or namespace name 'Mail' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)" I cant add system.net.mail…
xwpedram
  • 467
  • 1
  • 8
  • 20
0
votes
1 answer

Control temp file usage with codedom

I am working with .net and codedom in an environment where I would like to avoid (or preferably, eliminate) file system access. My current code: Private Sub ProcessCommand(ByVal command As String) Dim MyProvider As New VBCodeProvider Dim…
Sihan Zheng
  • 465
  • 4
  • 17
0
votes
1 answer

Codedom add resource

I'm compiling some source (it's a wpf window) with codedom. Now I want to add some resources (images) without dropping the file first. Is that possible? If yes, how? And how can i access the images within the new application? On request some more…
Mek
  • 65
  • 1
  • 9
0
votes
1 answer

Is there any way to create, compile and load dynamically an ASPX page

Ok, I'm wondering if it's possible to create an ASPX page on the fly. I mean, I've done that before*, but I knew beforehand which assembly I was creating, and I got this assembly referenced in the target project in advance (so I just repleace the…
Painy James
  • 805
  • 2
  • 13
  • 26
0
votes
1 answer

Why I can't add .NET DLLs at run time

Using CodeDOM I have something like this: CompilerParameters parameters = new…
Bohn
  • 26,091
  • 61
  • 167
  • 254
0
votes
1 answer

CodeDom sequence of methods

Could you say how I can do statement like below using CodeDOM (.net)? _myClass.Configure("MyNode").Action("param1", "param2"); Thanks.
evgeny-i
  • 50
  • 8
0
votes
4 answers

Custom attribute declaration for methods

I am using CodeDom to generate a class which include some methods. I was able to declare an attribute for my methods to look similar as what Pex does when it creates a parameterized unit test: [PexMethod] public void myMethod() However I would like…
Peter
  • 33
  • 1
  • 6
0
votes
1 answer

To place the script fetched from SQLite table in to my code at runtime ?

In sqlite i had placed the Function inside the table which i am fetching using c# code . I want to use that Function at runtime inside my code . (Eg : If i place function to add two number inside table , i want that code to be include in my code for…
0
votes
1 answer

Generate variable name by CodeDOM

HI all, Please help me with this: I have a form which contains my custom control. In the custom control, I have 2 collections referencing to the same DataSource to get data. My current CodeDOM serializer working like this: control1.Values.DataSource…
thethanghn
  • 319
  • 2
  • 5
  • 21
0
votes
1 answer

Refer custom class in the Auto generated class?

I've two classes that I am trying to generate code using CodeDom. First class (StudentModel), pretty straight forward, I am able to generate using CodeDom. In the second class, i.e. Student class, I am trying refer StudentModel class. StudentModel…
Naveen
  • 315
  • 2
  • 4
  • 15