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

CodeDom generic type constraint

Is there a way to generate a class constraint with CodeDom. Because when I use something like var method = new CodeMemberMethod(); var genericParam = new…
Fionn
  • 10,975
  • 11
  • 54
  • 84
12
votes
1 answer

SerializationStore not finding references

When trying to deserialize using the ComponentSerializationService, errors are populated that references were not found: public ICollection Deserialize(object serializationData) { var serializationStore = serializationData as…
JL.
  • 78,954
  • 126
  • 311
  • 459
12
votes
1 answer

creating enumeration using .NET's CodeDom

I want to create an Enumeration using CodeDom API. I have searched enough on the internet and I get results which are hardly of any use. What I want to generate is public enum bug_tracker_type { [Description("Bugzilla")] Bugzilla, …
Manish Sinha
  • 2,092
  • 2
  • 22
  • 33
12
votes
6 answers

How to programmatically parse and modify C# code

What I want to do is to read C# code, parse it, insert some method calls and compile it finally. Is it possible to convert C# source code (a list of strings) to CodeDOM objects?
ulrichb
  • 19,610
  • 8
  • 73
  • 87
11
votes
2 answers

C# CodeDom Automatic Property

I have a property created with CodeDom. How can I set it to being an automatic property instead of adding CodeFieldReferenceExpressions against a private member?
blu
  • 12,905
  • 20
  • 70
  • 106
11
votes
5 answers

Parsing C# code (as string) and inserting additional methods

I have a C# app I'm working on that loads it's code remotely, and then runs it (for the sake of argument, you can assume the app is secure). The code is C#, but it is sent as an XML document, parse out as a string, and then compiled and…
AlishahNovin
  • 1,904
  • 3
  • 20
  • 37
10
votes
1 answer

Unload CodeDom-compiled assembly

I have some C# code (let's call it "script") I am compiling at runtime. It uses an interface in my main program that I use to access its functions. Once compiling is done I have CompilerResults.CompiledAssembly in which case I can…
Nelson Rothermel
  • 9,436
  • 8
  • 62
  • 81
9
votes
2 answers

How do I select the target framework of a CodeDom compiler using C#?

So I have a CodeDOM compiler written in C# that's supposed to compile another application based on one of its resources. How would I change the target .NET framework of the resource (or of the outputted executable of the compiler)?
Alper
  • 1
  • 12
  • 39
  • 78
9
votes
2 answers

Can you explain very briefly what CodeDOM is and used for with a simple real life example?

Can you explain very briefly what CodeDOM is and used for with a simple real life example? A simple example that covers why would I need it as a developer, in what scenarios? Thanks
pencilCake
  • 51,323
  • 85
  • 226
  • 363
9
votes
2 answers

Why is JIT_MethodAccessAllowedBySecurity taking so much time?

I'm working on a C# application that allows users to basically import tables of data, and then enter their own formulas in a mini-language to compute new columns from the underlying data. These formulas are compiled into LINQ expression trees in the…
lvilnis
  • 518
  • 3
  • 13
9
votes
2 answers

How to force CSharpCodeProvider to compile for a specific target framework?

I've got a solution which contains c# projects, some netstandard 2.0 and others .net4.7. The startup project is of course net47. At one point, the project creates code using CodeDom and compiles it with CSharpCodeProvider. The problems is that on…
Alireza
  • 5,421
  • 5
  • 34
  • 67
9
votes
1 answer

CodeDom and Silverlight

Can Silverlight apps (the .xap file, the testpage.html, content resources along side a ClientBin, out of browser settings, etc) be created using only System.CodeDom from a regular .NET app? Meaning I have a console or winforms app that creates…
Stan
  • 746
  • 1
  • 17
  • 35
9
votes
2 answers

C# 4.0: Expression trees vs. CodeDom

What are the differences between Expression trees and CodeDom? Which should I use for which scenario?
Yaron Naveh
  • 23,560
  • 32
  • 103
  • 158
9
votes
1 answer

Parsing C# source code

I'm trying to parse a simple.cs source file using the following code: CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp"); var compileUnit = provider.Parse(File.OpenText(filename)); This gives me a NotImplementedException: "This…
Boris
  • 8,551
  • 25
  • 67
  • 120
9
votes
5 answers

Generate C# automatic properties with Codedom

is there a way Generate C# automatic properties with Codedom or maybe an other set of libreries that i can use ?
Hannoun Yassir
  • 20,583
  • 23
  • 77
  • 112
1
2
3
39 40