Skip to content

Settings and activity

4 results found

  1. 73 votes
    Vote

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
    You have left! (?) (thinking…)
    How important is this to you?

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
    An error occurred while saving the comment
    holdom commented  · 

    A very simple solution:

    - Download the ScriptCs.Engine.Roslyn NuGet package and it to MyExtensions.
    - Add the namespaces

    Then add this class to MyExtensions:

    public class CSrepl {

    private ScriptEngine sengine;
    private Session session;

    private string cmd;
    private string cmd_right = "";

    public CSrepl() {

    // Start the ScriptEngine and create a new session
    sengine = new Roslyn.Scripting.CSharp.ScriptEngine();
    session = sengine.CreateSession();

    // Basic operations within the session
    session.Execute(@"using System;");
    session.Execute(@"double ans = 0.0;");

    greetingMessage();
    startRepl();
    }

    private void startRepl()
    {
    while(!string.IsNullOrEmpty(cmd = Console.ReadLine()))
    {
    // Dump the entered expreassion
    cmd.Dump();

    if(cmd.Contains("="))
    {
    // Get the right hand part of the expresssion after the = sign
    cmd_right = cmd.Split('=')[1];

    // Add the semicolon at the end of the expression if it is missing
    if(!cmd.EndsWith(";"))
    {
    cmd = cmd + ";";
    }
    }

    try
    {
    if(session.Execute(cmd) != null) {
    // Execute an assignment like var a = 3.5;
    evalexpr(cmd);
    }
    else {
    // Evaluate an expression like 3 -5 * Math.PI
    evalexpr(cmd_right);
    }
    } catch (Exception e) {
    e.Dump();
    }
    }
    }

    public void evalexpr(string cmd)
    {
    try
    {
    if(session.Execute(cmd) != null)
    {
    // Evaluate the expression
    var res = session.Execute<double>(cmd);

    // Dump the result
    res.Dump("=");

    // assign value to the ans variable
    session.Execute(@"ans = " + res + @";");

    // add empty line
    ("").Dump();
    }
    } catch(Exception e) {
    e.Dump();
    }
    }



    private void greetingMessage()
    {
    ("----------------------------------------------------------------").Dump();
    ("LINQPad REPL - v.0.05 - Based on ScriptCs.Roslyn").Dump();
    ("-----------------------------------------------------------------").Dump();
    (" - Last update: 30.01.2014").Dump();
    ("--------------------------------------------------------------------------------------").Dump();
    ("Enter an expression like:").Dump();
    (" 4 + 5 ").Dump();
    (" var a = 3.5;").Dump();
    (" var d = 4 * Math.PI").Dump();
    ("in the black console window below.").Dump();
    ("--------------------------------------------------------------------------------------").Dump();
    ("You can omit the semicolon (;) at the end of a line. LINQPadREPL adds it automatically.").Dump();
    ("-------------------------------------------------------").Dump();
    ("").Dump();
    }
    }

    Open a new Query (C# Statements) and start the C# REPL within LINQPad:

    CSrepl repl = new CSrepl();

    It's a very simple solution and a lot of work remains until it is stable.

    holdom supported this idea  · 
  2. 154 votes
    Vote

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
    You have left! (?) (thinking…)
    How important is this to you?

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
    holdom supported this idea  · 
  3. 258 votes
    Vote

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
    You have left! (?) (thinking…)
    How important is this to you?

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
    holdom supported this idea  · 
  4. 18 votes
    Vote

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
    You have left! (?) (thinking…)
    How important is this to you?

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
    holdom supported this idea  ·