codedom

How to debug/break in codedom compiled code.

I have an application which loads up c# source files dynamically and runs them as plugins. When I am running the main application in debug mode, is it possible to debug into the dynamic assembly? Obviously setting breakpoints is problematic, since the source is not part of the original project, but should I be able to step into, or brea...

Work-around for C# CodeDom causing stack-overflow (CS1647) in csc.exe?

I've got a situation where I need to generate a class with a large string const. Code outside of my control causes my generated CodeDom tree to be emitted to C# source and then later compiled as part of a larger Assembly. Unfortunately, I've run into a situation whereby if the length of this string exceeds 335440 chars in Win2K8 x64 (9...

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 = new objA(); control1.CategoryNames.DataSource = new objA(); As you can see, t...

Public getter, protected setter with CodeDOM

Is it possible to generate a property with a public getter and a protected setter with CodeDOM? The goal is to achieve something similar to the following. [Serializable] public class Wrapper { public Wrapper() { } private string _Field; public string Field { get; protected set; } } I have a large COM based API for which I wish t...

C# String representation of method

Is there a way in .NET 3.0 (or earlier) to get a string representation of a method? I know that I can get an IL byte array from a MethodBody object, but I'm interested in getting a string that essentially represents the method body as it appears to my eyes in VS. I've poked around in the CodeDom namespace to see if there was a way to co...

C# 4.0, detect if a method is missing

I have a situation where i want to add LinePragmas to CodeDom objects. But some code dom objects have the LinePragma property and some don't. So I'm wondering if it's possible to use the dynamic keyword to detect if the property exists on the object (without throwing an exception) and if it does then add the pragma. Here is my current ...

Does a CodeDom Visual Basic .NET parser exist ?

Does somebody know if someone has created a Visual basic parser to CodeDom (ie, it takes VB.NET as input and create a CodeCompileUnit graph) ? SOLUTION I've retrieved the source code of SharpDevelop, and used their parser, it works just fine ! ...

Analyzing code structure using CodeDom??

Hi, I recently wrote a post here on Stackoverflow asking for some C# libraries that calculate metrics, mainly CC...unfortunately with no success. So I'm going to write it myself. I did a search on the web of what could be the best approach, but before starting I'd like to ask you on how you'd do it. I'm currently between two kind of ap...

How to initialize an array of arrays (or jagged array) using CodeDom ?

I'm trying to use CodeDom to generate C# (.Net 2.0) code that would do the following: int[][] myArray = new int[someSize][]; In CodeDom, initializing an array requires a CodeArrayCreateExpression. The MSDN says: If a language allows arrays of arrays, it is possible to create them by nesting a CodeArrayCreateExpression within a Cod...

How do we use .Net CodeDom to create a Dependency Object?

We are creating our own code generated to automate CRUD coding and we need to generate a class for use withing WPF. To do this, we need to create the class with fields/properties as dependency objects. How do we accomplish this with CodeDom in .Net 3.5? ...

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 between... codeClass.AddFunction("DoSomething", vsCMFunction.vsCMFunctionFunction, "bool"); an...

Programmatically Format Generated CodeDom Code

How can I make sure the CS generated from code like the following is formatted nicely, i.e as if we pressed CTRL-K D? It is C# We are doing something along the lines of: CodeMemberMethod membMethod = new CodeMemberMethod(); membMethod.Attributes = MemberAttributes.Static | MemberAttributes.Public; membMethod.Ret...

How do I create a class that inherits from another and passes a type parameter in CodeDom?

Here's what I want the resulting class declaration to look like: public sealed partial class Refund : DataObjectBase<Refund> { } } This code (snipped): targetClass = new CodeTypeDeclaration(className); targetClass.IsClass = true; targetClass.TypeAttributes = TypeAttributes.Public | TypeAttrib...

What controls version number inside codedom generated file?

What controls the version number inside of a codedom generated file? Some of our developers get: //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:2.0.50727.4005 while others get: //------------------------------------...

How do I expose member objects via using CodeDOM?

Everywhere I see tutorials on how to compile assemblies using the System.CodeDom namespace. But how can I access a member object of an assembly from a runtime compiled assembly (I'm not talking about accessing a class, I want to access a specific member variable)? In Microsoft Script Control it can be done with the AddObject method. I ...

Interpreting and/or receiving dotNet code at run-time

Html can contain little bits of Javascript embedded in it (e.g. defined in onclick event handlers). If I were writing an Html browser using a dotNet language like C#, what technologies or APIs could I use to run such Javascript fragments, given that I don't receive it until run-time (and receive it as string data, not as executable cod...

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 CreateInstance(Type). Once I am done using the script I would like to unload completely. From what I und...

CodeDOM support DataTable?

Hi, Does anyone know how to serialize a DataTable to CodeDOM? my use case is like below: object.DataSource = new DataTable()....; But this line seems not to be serialized in file designer.cs so that when I compile the form, values of datasource disappear. How to fix this? Thanks ...

System.CodeDom.CodeCompileUnit from System.Reflection.Emit.AssemblyBuilder instance

I'm looking at CodePlex code for TLBImp2 and want to generate C# source code from the IL emitted. Is there a way to get a System.CodeDom.CodeCompileUnit from a System.Reflection.Emit.AssemblyBuilder instance? ...

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. Now. Is it possible to convert C# source code (a list of strings) to CodeDOM objects? ...