dotnet/roslyn

Add Script property to InteractiveScriptGlobals and CommandLineScriptGlobals that returns a ScriptContext object

Open

#5,979 建立於 2015年10月14日

在 GitHub 查看
 (17 留言) (0 反應) (0 負責人)C# (4,257 fork)batch import
Area-InteractiveInteractive-ScriptingLogichelp wanted

倉庫指標

Star
 (20,414 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 256 個 PR)

描述

public class CommandLineScriptGlobals 
{
   public ScriptContext Script { get; }

   public CommandLineScriptGlobals(..., ScriptContext context)
}

public class InteractiveScriptGlobals 
{
   public ScriptContext Script { get; }

   public InteractiveScriptGlobals(..., ScriptContext context)
}

public class ScriptContext 
{
   public string GetPath([CallerFilePath]string path = null) { get; }
   public string GetDirectory([CallerFilePath]string path = null) { get; }

   public ScriptContext(string path)
}

The Script property would thus be available to scripts:

foreach (var arg in Script.Args) 
   Console.Writeline(File.ReadAllText(Path.Combine(Script.GetDirectory(), arg)));
...

In future we can add more features to this context:

class ScriptContext 
{
    Task<object> EvalAsync(string code, object globals);
}

F# has a similar concept: "fsi" object:

image

貢獻者指南