ScriptCs is a great yet simple to use framework for writing and executing C# scripts.
TL;DR Chocolatey + NuGet + Roslyn = ScriptCs ScriptCs + Command Prompt = C# REPL
Beeing able to write and freely execute C# scripts is a great opportunity and can be a time saver. What I lack more at this stage of development of ScriptCs is a simple toolset to implement basic user interactions. I've sterted a new project on GitHub called ScriptCS-GUI. At the moment it holds some vanilla C# scripts but I wish to evolve it to a full featured Script Pack.
As a starter I implemented classic interactions such showing an OpenFileDialog and a SaveFileDialog. In the following example the Console asks the user to select a file and then writes the selected file name.
> #load "gui.csx" // <-- load gui.csx > var file = Gui.OpenFileDialog(); // <-- show a classic Open File dialog and wait the user to pick a file > file // <-- write the selected file name on console C:\temp\foobar.txt
The following script shows you how to read a folder name from the command argument and use it with the Gui.OpenFileDialog helper.
#load "../script/gui.csx" // Run with: // scriptcs -script "{filename}.csx" -- c:\some-path var folder = ScriptArgs.FirstOrDefault(); // <-- the starting folder name var path = Gui.OpenFileDialog(folder); Console.WriteLine("You selected: '{0}'.", path ?? "nothing");
Launch the script as shown in the picture and enjoy your interaction... :)
No comments:
Post a Comment