Announcement

Collapse
No announcement yet.

Compiling a single C# method like a script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Compiling a single C# method like a script

    Hello,

    I'm testing a concept similar to Deck.NET, but also different.

    The idea is that the user is logged into a web- based editor written in Bridge.NET. The user can click on a property and then choose a fixed property value, or a scripted property value. At the moment, if the user chooses scripted he will have to write plain JavaScript. Which works ok.
    But ideally I'd like the scripting language to be C# (less verbose and compile-time checked).

    So I'd like the user to write something like:
    1 + 1
    -- or --
    var temp = DateTime.Now;
    temp.AddDays(1);
    return temp;
    Similar to the Roslyn scripting API in C#.

    Then I'd like to send that code to the server and let Bridge.NET compile it to JavaScript.
    Which is then stored in that property for later execution on a client viewing that property value.

    Looking for the least complex approach of doing this. Here are some possibilities:
    • Use the Bridge CLI interface on the server. Place the C# script inside a method (named MyMethod) with the return type "Object" in Program.cs, compile it to MyProject.js, then use Regex or similar to extract the code within MyMethod to send back to the client for invoke. This setup could be run inside a Docker image on the server (that is built from the repository each revision).
    • Or perhaps referencing Bridge.Min directly from the IIS server invoking the right stuff required to compile the script. Could be more complicated to code, but could mean less complicated runtime if all could be done in memory.
    • Third option?
    A complicating factor is that there will be dependencies to previously compiled Bridge.NET assemblies with custom classes. This is no issue for the client because it has these js dependencies already loaded, but the Bridge compiler on the server needs to know about these dependencies.

    Which solution do you think will be the simplest and best?
    Has similar stuff been done before?


    Best regards

    #2
    If you can hook up the Bridge CLI to run the compilation, that's likely going to provide excellent performance and plenty of configuration.

    The Bridge Docker image might be useful to you too:

    https://hub.docker.com/r/bridgedotnet/bridge/

    The following forum thread provides some further details on using the Bridge Docker container:

    https://forums.bridge.net/forum/comm...using-net-core

    Hope this helps.
    Last edited by geoffrey.mcgill; 2019-05-05 @ 02:19 AM.

    Comment


      #3
      Thanks! Didn't realize a Docker image already existed. Will test!

      Is there a way to build scripts using Bridge CLI that just builds the method/delegate itself without registering the assemblies/defines?

      If not, I guess I can write some code to extract the content of the method.

      Comment

      Working...
      X