codedom

Understanding the various options for runtime code generation in C# (Roslyn, CodeDom, Linq Expressions, …?)

不羁岁月 提交于 2019-12-03 20:33:01
I'm working on an application where I'd like to dynamically generate code for a numerical calculation (for performance). Doing this calculation as a data driven operation is too slow. To describe my requirements, consider this class: class Simulation { Dictionary<string, double> nodes; double t, dt; private void ProcessOneSample() { t += dt; // Expensive operation that computes the state of nodes at the current t. } public void Process(int N, IDictionary<string, double[]> Input, IDictionary<string, double[]> Output) { for (int i = 0; i < N; ++i) { foreach (KeyValuePair<string, double[]> j in

CodeDom and collection initializers

家住魔仙堡 提交于 2019-12-03 20:12:48
Is there a way to generate a dictionary initializer using the C# CodeDom? Are those supported at all? I would like to have: private IDictionary<string, string> map = new Dictionary<string, string> { { "Name", "Value" }, ... }; This is not possible using the CodeDom constructs. They were not updated for collection initializers. LukeH has an excellent blog post on the subject of 3.5 features and the CodeDom http://blogs.msdn.com/b/lukeh/archive/2007/07/11/c-3-0-and-codedom.aspx You can do it but its possibly the worst nightmare ever.. Here is how I am doing it currently. (Updated my answer to

Why is JIT_MethodAccessAllowedBySecurity taking so much time?

半腔热情 提交于 2019-12-03 17:50:07
问题 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 engine, which the .NET 4.0 expression tree library then presumably compiles into IL so they can be executed. We've started using our engine for some high-volume ticking data recently, and we're finding the speed of these compiled expression trees

Which .NET Programming Languages Have a CodeDom Provider?

孤人 提交于 2019-12-03 15:45:39
Aside from C#, VB.NET, C++ (Managed and C++/CLI), and F#, which .NET programming languages have their own CodeDom provider? I thought about making one for UnrealScript, but I run into odd issues like the fact that CodeBinaryOperatorType doesn't include an exclusive-or operation. The new expression trees in .NET 4 seem like a much better representation of what features the CodeDom should offer at a block level (as in a block of statements that makes up a function body). I think we need a new CodeDom that takes the outer portions of System.CodeDom and uses the internals of System.Linq

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

孤街浪徒 提交于 2019-12-01 20:46:13
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 | TypeAttributes.Sealed; targetClass.IsPartial = true; //partial so that genn'ed code can be safely modified targetClass.TypeParameters.Add(new CodeTypeParameter{ Name=className}); targetClass.BaseTypes.Add(new CodeTypeReference { BaseType = "DataObjectBase", Options = CodeTypeReferenceOptions.GenericTypeParameter });

Use DLR to run code generated with CompileAssemblyFromSource?

假装没事ソ 提交于 2019-12-01 18:11:20
问题 Following up on this excellent answer, I'm wondering if the DLR using the dynamic keyword can allow a less verbose way of writing code for the generated assembly. For example, can the aforementioned answer's code: using (Microsoft.CSharp.CSharpCodeProvider foo = new Microsoft.CSharp.CSharpCodeProvider()) { var res = foo.CompileAssemblyFromSource( new System.CodeDom.Compiler.CompilerParameters() { GenerateInMemory = true }, "public class FooClass { public string Execute() { return \"output!\";

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

亡梦爱人 提交于 2019-12-01 17:27:49
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 CodeDOM stands for Code Document Object Model. Basically, it is your code represented by a hierarchical tree of objects, a model.. Consider a method with some statements in it: int Foo(int bar) { int i = 0; if ( bar == 1 ) i = 1; return i; } This would result in a DOM as follows: method foo declaration if (expression) assignment return A model like this that represents your code allows you to perform various

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

前提是你 提交于 2019-12-01 16:23:48
问题 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 回答1: CodeDOM stands for Code Document Object Model. Basically, it is your code represented by a hierarchical tree of objects, a model.. Consider a method with some statements in it: int Foo(int bar) { int i = 0; if ( bar == 1 ) i = 1; return i; } This would result in a DOM as follows: method foo declaration if

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

不羁的心 提交于 2019-12-01 04:46:29
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 (926240 in Win2K3 x86), the C# compiler exits with a fatal error: fatal error CS1647: An expression is too long or complex to compile near 'int' MSDN says CS1647 is "a stack overflow in the compiler" (no pun intended!). Looking more closely I've determined that the

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

牧云@^-^@ 提交于 2019-12-01 01:48:48
问题 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 (926240 in Win2K3 x86), the C# compiler exits with a fatal error: fatal error CS1647: An expression is too long or complex to compile near 'int' MSDN says CS1647