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

Passing and using a list in CodeDom dynamic method

I am trying to use a simple static method to return an object to dynamically evaluate an expression. I have followed the advice outlined in the examples here: http://www.blackwasp.co.uk/RuntimeCompilation_2.aspx For basic expressions this is…
spotvader
  • 35
  • 4
0
votes
1 answer

Are chained method invocations possible with System.CodeDom?

Ist it possible to generate c# code like this with System.CodeDom? public MyClass() // ctor { Foo().Bar(); } I only get the following code blocks public MyClass() // ctor { Foo(Bar()); } public MyClass() // ctor { Foo(); Bar(); }
Antineutrino
  • 1,093
  • 3
  • 10
  • 26
0
votes
2 answers

Get the stored procedure schema

I'm trying to write a framework to generate entities from an existing database. I've already implemented all the code to generate the entities from the tables and it works well. Now I'm looking for a solution to retrieve all the information I need…
simoneL
  • 602
  • 1
  • 7
  • 23
0
votes
2 answers

Generate custom class at design time

I have a component which has a collection of objects (DataProviders). Each DataProvider has a unique name set by the user at design time. How can I make the designer generate a class into an additional file which contains the names of the…
Pawel
  • 3
  • 3
0
votes
0 answers

VB CompileAssemblyFromSource Win 8.1 error

Googled problem, but seems like I'm the first who encountered it yet... Same of code compiles in Windows 7 & 8 environment, but fails in Windows 8.1. Dim x As Object = Windows.Forms.DialogResult.Cancel If it is like that - win7 and win8 compile it…
0
votes
0 answers

Merging custom CodeDOM reference

I need a way of merging my custom DLL with my CodeDOM output automatically when it's build. I think about using ILMerge, but, it's there a better way?
0
votes
1 answer

add assembly from resources with ResourceManager

I would like to add an assembly with ResourceManager I have this code but it obviously doesn't work. Please help! Loading the resource and trying to use it as an assembly: static ResourceManager resourceManager = new ResourceManager("res",…
sanchixx
  • 275
  • 2
  • 5
  • 12
0
votes
0 answers

Calling Web Service Object WebMethod using CodeDom

Here is an example of how I am calling a web method for a web service for an object, using VB.NET. Dim tt As New GetSurveyLink Dim result As String = tt.GetSurveyLinkString(New List(Of String)({"A","B"}) Can someone tell me how to use the Class I…
open7
  • 43
  • 7
0
votes
1 answer

How to get runtime error line number in CodeDom?

For example, the code below can complile ok, but throw an exception at runtime. My question is, how to get the runtime error line number ? Thanks. using System; using System.Collections.Generic; using System.Text; namespace mytempNamespace { …
yiketudou
  • 1
  • 2
0
votes
0 answers

FileLoadException when using CompileAssemblyFromDom

I believe this is a permissions issue but I don't know how to solve it, I receive the following exception: System.IO.FileLoadException: LoadFrom(), LoadFile(), Load(byte[]) and LoadModule() have been disabled by the host. at…
Anupheaus
  • 3,383
  • 2
  • 24
  • 30
0
votes
1 answer

CodeEntryPointMethod doesn't work with Winforms

So I'm trying to compile/build an executable through C#/CodeDom Scripting. I'm trying to have the new application (The one to be compiled) set to have it's main method, to use some methods like Application.Run() to actually run the Windows Form…
Kevin Jensen Petersen
  • 423
  • 2
  • 22
  • 43
0
votes
1 answer

Can't find suitable Main method

I'm trying to create a Windows Form Application, that can create another Windows Form Application. But the error i'm getting when i'm trying to compile with CodeDom in the c# code, is a weird one. 'kjpUnityGameLauncherTemplate.RunLauncher' does not…
Kevin Jensen Petersen
  • 423
  • 2
  • 22
  • 43
0
votes
1 answer

NRefactory add namespace to typedeclaration

Currently I'm working on a project with NRefactory. We're filtering typedeclarations like 'Class' and 'Interface' out of a .cs file. We would like to place these typedeclarations into a custom namespace, but for some reason it's not working. Is…
Mittchel
  • 1,896
  • 3
  • 19
  • 37
0
votes
0 answers

Create UserControl with CodeBehind at runtime in Asp.Net

How to create a usercontrol and its codebehind from source file(s) at runtime and load into a panel? I'm pretty sure using CodeDom could solve this, but not quite sure how to go about it. Can anyone provide a simplified example for this? Thanks in…
Troy Mitchel
  • 1,790
  • 11
  • 50
  • 88
0
votes
1 answer

how to: codedom ignoring warnings in vb.net

im trying to build an application with using Code-Dom, the problem is that the compiler treats warnings as errors, i tried to specify it's parameters but with no luck Dim Parameters As New CompilerParameters() Parameters.WarningLevel =…
user2618553
  • 115
  • 1
  • 2
  • 8