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

Is it possible to construct an object by reading source code?

Background I have a few scripts that run as part of my build process that look at the various source code files and generate some more source code for me. The scripts use CodeDom to generate them and they read the .cs files using a simple text…
quip
  • 3,666
  • 3
  • 32
  • 45
0
votes
1 answer

Recursive type constraints in CodeDom

We are writing a proxy generator using CodeDom and it appears that generic types in a recursive constraint are not being generated. The code in question should just pass the constraint through as it is: void…
ilen
  • 69
  • 8
0
votes
1 answer

Public variable interference between InMemory generated assemblies from CodeDom

Users are able to launch multiple instances of InMemory assemblies from a main application. The problem is the public variables in the InMemory assemblies seem to overwrite each other. Is there a way to fix this? I also tried renaming the Namespace…
Troy Mitchel
  • 1,790
  • 11
  • 50
  • 88
0
votes
0 answers

Using CodeDom to save a class to the solution

Is it possible? I have good source code, and I have instantiated an object from the dynamically generated source code, but I need to place this class into my solution.
websculpt
  • 53
  • 9
0
votes
0 answers

Compiling the same files twice programatically in C# throws "Could not find part of path" error

I'm using C# and CodeDOM to compile code programatically by exporting CodeDOM representations to strings and using Microsoft.CSharp.CSharpCodeProvider provider = new CSharpCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); To…
mtrc
  • 1,317
  • 3
  • 16
  • 39
0
votes
1 answer

Including C# files when compiling programmatically from a string

I was previously exporting CodeDOM CompilationUnits to files, and then reading those files back in to compile them using a CSharpCodeProvider. Today I refactored the code so that the CodeDOM is exported to a String: public static string…
mtrc
  • 1,317
  • 3
  • 16
  • 39
0
votes
1 answer

Build C# Application runtime and get the results

I want to compile a C# console application inside my application and get the returned result somehow. I want this to happen silently(i don't want the console to actually show etc.) Lets say i have this code private Assembly BuildAssembly(string…
Georgi-it
  • 3,676
  • 1
  • 20
  • 23
0
votes
1 answer

CodeDomProvider failed to resolve my assemblies in website Bin folder when dynamically compiling code

All, I have asp.net website and in my bin folder I have all neccessary assemblies that my dynamically compiled code references. I compile my code at run time using CodeDomProvider. When I compile my expression with the following…
ActiveX
  • 1,064
  • 1
  • 17
  • 37
0
votes
1 answer

How to use " in CodeDom Source Code?

I want to append this Line to the source code which will be compiled : Temp.AppendLine(@"[assembly: AssemblyDescription("[DESCRIPTION]"]);"); But you see the [DESCRIPTION] is not in the string too... Instead of the [DISCRIPTION] I want to use the…
The Flash
  • 63
  • 1
  • 6
0
votes
1 answer

MessageBox won't show up in code generated by CodeDom

I coded a builder in C# which compiles a code with CodeDom. The compiled .exe has to show up an MessageBox, but it doesnt do that. Everything works fine, the .exe is compiled and generated, but the output doesnt work (MessageBox doesnt appear). Here…
The Flash
  • 63
  • 1
  • 6
0
votes
2 answers

C# CodeDom use TextBox from the Builders Form

Maybe you didnt understand the title, but my question is : I have an Builder. This builder creates an output (.exe) which uploads my pictures folder to the FTP-Server. I actually want to know how to use the textboxes from the builders form to get…
GumGun
  • 15
  • 1
  • 1
  • 5
0
votes
2 answers

C# CodeDom Cant type in "

I want to compile a code with codedom which should connect to my ftp server. But I cant type in the credentials because of the ""... Look here : Temp.AppendLine(@"request.Credentials = new NetworkCredential("userid","userpassword");"); If I type "…
GumGun
  • 15
  • 1
  • 1
  • 5
0
votes
1 answer

Unable to compile code output because of some reference assembly goofups

My issue goes like this: There is a project called myframework. It has some extension methods defined in it as follows: namespace myframework { public static class Helpers { public static bool ContainsAll(this string obj, string[]) …
deostroll
  • 11,661
  • 21
  • 90
  • 161
0
votes
1 answer

csharpcodeprovider unable to compile when assembly added to gac

My solution structure in vs is as follows. MyRuleEngineFramework RulesEditor MyRuleEngineFramework is a class library. RulesEditor is a winforms project. The latter references the former, however, that assembly is not consumed inside of the editor…
deostroll
  • 11,661
  • 21
  • 90
  • 161
0
votes
1 answer

how to avoid the brackets appearing in the generated method statement

I am trying to do an assign statement while trying to generate some c# code using codedom. Here are the statements I wrote: inputmethod.Name = "CaptureInput"; inputmethod.Attributes = MemberAttributes.Public |…
deostroll
  • 11,661
  • 21
  • 90
  • 161