Roslynpad is a tool for executing .NET code designed to be lightweight, simple, and very easy to use.
One of the things that is criticized about .NET compared to other development solutions such as NodeJs or Python is its relative complexity or slowness when creating a new project.
And, in reality, they are not wrong. The truth is that creating a new application in .NET usually requires more work and effort than in other alternatives, which makes it not used as much in “lightweight” script-like programs.
Roslynpad is an editor developed in CSharp and Avalonia. It is cross-platform and works on Windows, Linux, and macOS.
It has similar features to the commercial program LINQpad, which Roslynpad is inspired by. Although LINQpad is a much more advanced solution, it is a paid one.
Roslynpad includes autocomplete, error highlighting, and correction suggestions. Additionally, NuGet packages can be added, although only from public repositories.
Roslynpad is an open-source development and all the code is available on the project’s website https://roslynpad.net/ or on its GitHub https://github.com/roslynpad/roslynpad.
In short, it is a very interesting tool for working with C# and running small script-like applications in a comfortable and simple way.
Testing Roslynpad
Let’s see the use of Roslynpad with a couple of simple examples. To do this, we just have to open a new script and write the following.
Console.WriteLine("Hello from Roslynpad");
If we run the code, we will see the output in the command console. A very useful tool is Dump(), which appears as an extension method for any object, and allows us to display the results. For example,
var myList = new [] {1, 2, 3, 4};
myList.Where(x=> x > 2).Select(x=> x * 10).Dump();
Of course, we can also create somewhat more complex programs, with functions, classes, assemblies, and other .NET tools.
For example, in this simple script, we would rename all the files in a folder in the form of 0.txt, 1.txt, …
var path = @"C:\myPath";
var myFiles = Directory.EnumerateFiles(path).ToArray();
for (int i = 0; i < myFiles.Length; i++)
{
Rename(myFiles[i], @$"{path}\{i}.txt");
}
public static void Rename(string source, string newName)
{
var fileInfo = new System.IO.FileInfo(source);
fileInfo.MoveTo(fileInfo.Directory.FullName + "\\" + newName);
}