codedom

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

女生的网名这么多〃 提交于 2020-01-01 06:57:10
问题 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

vb.net Replace existing class with CodeDoms generated class

限于喜欢 提交于 2019-12-25 17:55:33
问题 I've class like this (it's just example) class child inherits parent1 end class and then at runtime i want change become like this class child inherits grandfatherclass end class I've been trying with code like this, sadly it's still inherits from parent1 Dim onewclass As CodeDomProvider = CodeDomProvider.CreateProvider("VB") Dim objCompilerParameters As New CodeDom.Compiler.CompilerParameters Dim classString as string = "class child" & vbnewline & _ " inherits grandfatherclass" & vbnewline &

Possible to use C# codeDOM to call back to pre-compiled functions?

旧时模样 提交于 2019-12-24 03:32:13
问题 I'm working on a silly game where the player controls their character by programming procedures for it to follow. I'm using C# codeDOM to compile the code the player writes and I'd like for the player to be able to call functions written into the pre-compiled part of the software. For example: Player-written code to be compiled at run-time by codeDOM: namespace AutoCrawl { public class Player { public void Go_Up() { Move("Up"); } } } My pre-compiled code: private void compileUserCode() {

How to improve compile time using CSharpCodeProvider

旧时模样 提交于 2019-12-23 02:19:12
问题 I have an application where user can create its own formula it works fine for all case but when i have DateTime Fields in my formula the compilation part of the code take around 132 ms for one formula where at the same time i have 31 formula each with different value. using Microsoft.CSharp; using System; using System.CodeDom.Compiler; namespace abc { public class Abc { static void Main() { var code = @" using System; namespace First { public class program { public static int Main() { if

Import namespaces in a CodeSnippetCompileUnit

a 夏天 提交于 2019-12-22 12:25:32
问题 When using a CodeCompileUnit to generate code via the CodeDOM, you can import namespaces by creating a CodeNamespace separate from the namespace in which you're defining your type(s). Using the Imports property allows you to add the namespaces you desire. If you add the CodeNamespace to the CodeCompile unit, the imports will appear at the top of the file generated by the CodeDOM. For instance, using a CSharpCodeProvider to compile the following CodeDOM graph: CodeCompileUnit compileUnit = new

Codedom and string handling

二次信任 提交于 2019-12-22 09:10:15
问题 I've researched on this but couldn't find anything solid and wanted to see if someone can point me in the right direction. I'm trying to see if Codedom can handle strings and concantination between different languages, without me setting up conditional strings per language. For example, I need to generate the following exactly as shown below in both C# and VB.NET via Codedom: C# errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); System.Windows.Browser.HtmlPage.Window.Eval("throw

Setting file version for a codeDOM file

邮差的信 提交于 2019-12-21 22:38:34
问题 I'm looking for ANY means of setting the file version for an exe file generated using codeDOM. Mine always comes out as 0.0.0.0. Programatically would obviously be preferred, but at this point anything would be better than nothing. 回答1: The version of the compiled assembly is controlled by the AssemblyFileVersion attribute. You just need to make sure this is included as part of your CodeDom tree when you compile. You can set this by adding the attribute into the CodeCompileUnit

Adding Assemblies to BuildManager using CodeDOM causing intermittent errors

老子叫甜甜 提交于 2019-12-21 19:47:42
问题 I am using CodeDOM to create an in-memory assembly at run time like so: public Assembly Compile(CodeCompileUnit targetUnit) { string path = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath); var compilerParameters = new CompilerParameters { GenerateInMemory = true, IncludeDebugInformation = true, TreatWarningsAsErrors = true, WarningLevel = 4, CompilerOptions = "/nostdlib", }; //For system.dll compilerParameters.ReferencedAssemblies.Add(typeof(System

T4 vs CodeDom vs Oslo [closed]

喜欢而已 提交于 2019-12-21 17:32:53
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . In an application scaffolding project on which I'm working, I'm trying to decide whether to use Oslo, T4 or CodeDom for generating

Is any simple way to create method and set its body dynamically in C#?

偶尔善良 提交于 2019-12-21 05:12:17
问题 I hold body of method in string. I want to create method dynamically. But I don't know, how to set its body. I saw very tedious way using CodeDom. And I saw using Emit with OpCodes. Is any way to use ready code from string variable? string method_body = "return \"Hello, world!\";"; //there is method body DynamicMethod dm = new System.Reflection.Emit.DynamicMethod("My_method", typeof(string), new Type[] { }); //any way to create method dynamically //any way to set body string result = (string