FastSharp - Write it, Execute it
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.
Comments
Anonymous
February 11, 2008
PingBack from http://msdnrss.thecoderblogs.com/2008/02/12/Anonymous
February 12, 2008
The comment has been removedAnonymous
February 12, 2008
Ricordo che un po' di tempo fa c'era in giro un tool simile. In sostanza, si tratta di un piccoloAnonymous
February 24, 2008
Links of the Week #25 (week 8/2008)Anonymous
February 24, 2008
Development Top-10 Application-Design Mistakes - How not to design your UI. It's hard not to nodAnonymous
July 14, 2010
How is this related to developing on Linux? Thumbs down on StumbleAnonymous
August 08, 2010
Hi! Well in your example I see a little bug: even if the ToBinary() method returns the same result in localtime and UTC mode, you are invoking the DateTime.Now twice, therefor the result will always differ.. You should write DateTime nowTime = DateTime.Now; Console.WriteLine(nowTime.ToBinary()); Console.WriteLine(nowTime.ToUniversalTime().ToBinary()); But I like the idea of the application. Thanks for the advice.