UPDATE: New version on FastSharp that includes a Windows 7 Gadget! Learn more here.
Last year I wrote this program which I named FastSharp. It is a text editor which lets you compile and run C# code that would normally exist inside a method. The inspiration for this came from getting tired of opening up Visual Studio and creating a project when all I want to do is execute one line of code and see what it outputs.
A prime example of this happened today (which is what sparked me to finally post this program). My co-worker Bertan and I were talking about the System.DateTime object in .NET. We were wondering if the ToBinary() method would return the same value regardless whether the datetime object was in local time or in UTC mode. He was about to fire up Visual Studio and create a project just to write this two line program when I showed him FastSharp.
First I opened the program:
Then I entered this two line program and hit the run button:
I got an error because I forgot the capitalize the second t in ToUniversalTime(). So, I corrected that and then ran it again:
And then we had our answer. The to outputs are not the same so they do produce different results.
The way FastSharp works is pretty simple. It takes whatever you enter and wraps it in a Main method which is then wrapped in a class which then has a list of import statements appended above it (configurable through the settings dialog). It then compiles the code using the Microsoft.CSharp.CSharpCodeProvider class and executes it. Because FastSharp wraps the code inside of a method block you can only write code that would normally compile inside of a method. (No classes or methods).
Things To Consider and Future Consideration
- FastSharp can only do console output not input. I was unable to figure out how to make Console.ReadLine() work inside the program. This will be an important future feature if someone can figure it out.
- FastSharp compiles only C# code but it is not hard to make it work for Visual Basic, which would also be a nice feature upgrade.
- FastSharp uses the out-of-the-box winforms RichTextBox control as the code editor. It would be nice to replace this with a code editor that color coded or even give intellisense 🙂
Give Me! Give Me! Give Me!
To download both the FastSharp binary and source code visit Click Here.