Click here to Skip to main content
15,886,806 members
Home / Discussions / C#
   

C#

 
AnswerRe: Multi programming language Pin
Patrice T5-Jun-20 13:35
mvePatrice T5-Jun-20 13:35 
QuestionAre there any good apple ipad c# compilers? Pin
Ultra9603-Jun-20 1:20
Ultra9603-Jun-20 1:20 
AnswerRe: Are there any good apple ipad c# compilers? Pin
OriginalGriff3-Jun-20 1:25
mveOriginalGriff3-Jun-20 1:25 
QuestionHow can I compile code in runtime faster than CSharpCodeProvider()).CreateCompiler().CompileAssemblyFromDom? Pin
arnold_w2-Jun-20 5:31
arnold_w2-Jun-20 5:31 
AnswerRe: How can I compile code in runtime faster than CSharpCodeProvider()).CreateCompiler().CompileAssemblyFromDom? Pin
OriginalGriff2-Jun-20 5:50
mveOriginalGriff2-Jun-20 5:50 
GeneralRe: How can I compile code in runtime faster than CSharpCodeProvider()).CreateCompiler().CompileAssemblyFromDom? Pin
arnold_w2-Jun-20 9:40
arnold_w2-Jun-20 9:40 
AnswerRe: How can I compile code in runtime faster than CSharpCodeProvider()).CreateCompiler().CompileAssemblyFromDom? Pin
arnold_w2-Jun-20 22:59
arnold_w2-Jun-20 22:59 
AnswerRe: How can I compile code in runtime faster than CSharpCodeProvider()).CreateCompiler().CompileAssemblyFromDom? Pin
arnold_w3-Jun-20 2:39
arnold_w3-Jun-20 2:39 
I also tried the following, which is based on .net assembly - C# CompilerResults GenerateInMemory? - Stack Overflow[^], but it appears to compile even slower (I measured 208 ms):
C#
public static class MyClass
{
    public static void Example()
    {
        Stopwatch watch = System.Diagnostics.Stopwatch.StartNew();
        dynamic instance = CompileSource(
            "namespace Test" +
            "{" +
            "    public class DynamicCompile" +
            "    { " +
            "       public void logHelloThere()" +
            "       {" +
            "           System.Diagnostics.Debug.WriteLine(\"Hello there\");" +
            "       }" +
            "    }" +
            "}").TryLoadCompiledType("Test.DynamicCompile");
        instance.logHelloThere();
        long elapsedMs = watch.ElapsedMilliseconds;
        Debug.WriteLine("Elapsed: " + elapsedMs);
    }


    public static CompilerResults CompileSource(string sourceCode)
    {
        var csc = new CSharpCodeProvider(
            new Dictionary<string, string>() { { "CompilerVersion", "v4.0" } });

        var referencedAssemblies =
                AppDomain.CurrentDomain.GetAssemblies()
                .Where(a => !a.FullName.StartsWith("mscorlib", StringComparison.InvariantCultureIgnoreCase))
                .Where(a => !a.IsDynamic) //necessary because a dynamic assembly will throw and exception when calling a.Location
                .Select(a => a.Location)
                .ToArray();

        var parameters = new CompilerParameters(referencedAssemblies);

        return csc.CompileAssemblyFromSource(parameters, sourceCode);
    }


    public static object TryLoadCompiledType(this CompilerResults compilerResults, string typeName, params object[] constructorArgs)
    {
        if (compilerResults.Errors.HasErrors)
        {
            Debug.WriteLine("Can not TryLoadCompiledType because CompilerResults.HasErrors");
            return null;
        }

        var type = compilerResults.CompiledAssembly.GetType(typeName);

        if (null == type)
        {
            Debug.WriteLine("Compiled Assembly does not contain a type [" + typeName + "]");
            return null;
        }
        return Activator.CreateInstance(type, constructorArgs);
    }
}

AnswerRe: How can I compile code in runtime faster than CSharpCodeProvider()).CreateCompiler().CompileAssemblyFromDom? Pin
Gerry Schmitz3-Jun-20 6:40
mveGerry Schmitz3-Jun-20 6:40 
GeneralRe: How can I compile code in runtime faster than CSharpCodeProvider()).CreateCompiler().CompileAssemblyFromDom? Pin
arnold_w3-Jun-20 9:30
arnold_w3-Jun-20 9:30 
GeneralRe: How can I compile code in runtime faster than CSharpCodeProvider()).CreateCompiler().CompileAssemblyFromDom? Pin
kalberts3-Jun-20 10:10
kalberts3-Jun-20 10:10 
GeneralRe: How can I compile code in runtime faster than CSharpCodeProvider()).CreateCompiler().CompileAssemblyFromDom? Pin
arnold_w3-Jun-20 10:34
arnold_w3-Jun-20 10:34 
QuestionConverting InAppBilling.Plugin to Amazon Pin
Exoskeletor2-Jun-20 3:52
Exoskeletor2-Jun-20 3:52 
AnswerRe: Converting InAppBilling.Plugin to Amazon Pin
OriginalGriff2-Jun-20 4:38
mveOriginalGriff2-Jun-20 4:38 
GeneralRe: Converting InAppBilling.Plugin to Amazon Pin
Exoskeletor2-Jun-20 4:56
Exoskeletor2-Jun-20 4:56 
GeneralRe: Converting InAppBilling.Plugin to Amazon Pin
OriginalGriff2-Jun-20 5:18
mveOriginalGriff2-Jun-20 5:18 
GeneralRe: Converting InAppBilling.Plugin to Amazon Pin
Exoskeletor2-Jun-20 7:40
Exoskeletor2-Jun-20 7:40 
AnswerRe: Converting InAppBilling.Plugin to Amazon Pin
Kris Lantz2-Jun-20 9:13
professionalKris Lantz2-Jun-20 9:13 
GeneralRe: Converting InAppBilling.Plugin to Amazon Pin
Exoskeletor2-Jun-20 9:24
Exoskeletor2-Jun-20 9:24 
QuestionState machine performance woes in .NET Pin
kalberts2-Jun-20 3:04
kalberts2-Jun-20 3:04 
AnswerRe: State machine performance woes in .NET Pin
kalberts2-Jun-20 3:41
kalberts2-Jun-20 3:41 
GeneralRe: State machine performance woes in .NET Pin
F-ES Sitecore2-Jun-20 4:08
professionalF-ES Sitecore2-Jun-20 4:08 
QuestionProblem with Currency format Column Calculation in my dGV in C# Winform Application. Pin
Member 1467808531-May-20 6:47
Member 1467808531-May-20 6:47 
AnswerRe: Problem with Currency format Column Calculation in my dGV in C# Winform Application. Pin
OriginalGriff31-May-20 20:34
mveOriginalGriff31-May-20 20:34 
QuestionMulti threading in C# Pin
bjwaldo28-May-20 9:21
bjwaldo28-May-20 9:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.