Monday, 1 October 2012

VisualStudio C# REPL - O2 Platform

Checkout the new O2 VisualStudio Extension published at VisualStudio Gallery: VisualStudio C# REPL - O2 Platform

As you can see by the title and menu items, the focus of this extension is on the C# REPL environment that allows the real time coding of VisualStudio :)

Please give it a test drive. If you find any issues drop me a line or add them here.

Also checkout this reddit thread on this topic for more comments and code samples




Description from VisualStudio Gallery page (Copy and Paste)


This extension provides a C# REPL Scripting environment (based on O2 Platforms's FluentSharp APIs).

In addition to being able to write and execute quick C# snippets (in a REPL environment), you can program VisualStudio IDE in real time! 

Here is a code sample that shows how to use FluentSharp's VisualStudio API to manipulate multiple parts of the VisualStudio IDE:

//get a reference to the VisualStudio API
var visualStudio = new VisualStudio_2010();
//write an Error and Warning messages to the 'Error List' VisualStudio Window
visualStudio.errorList().add_Error("I'm an Error");
visualStudio.errorList().add_Warning("I'm an Warning");
//open a text file
visualStudio.open_Document("a text file".saveWithExtension(".exe"));
//open a C# file
visualStudio.open_Document(@"VS_Scripts\O2_Platform_Gui.cs".local());
//open a WebBrowser
visualStudio.open_WebBrowser(@"http://diniscruz.blogspot.co.uk/search/label/O2%20Platform");
//add a top Menu
visualStudio.dte().add_TopMenu("A new Menu")
.add_Menu_Button("Ask me a question", ()=> "Hi {0}".alert("What is your name?".askUser()));
//change the main title
visualStudio.mainWindow().title(visualStudio.mainWindow().title() + " - Now with REPL");
//change the status bar
visualStudio.statusBar("C# script example complete");
//return the EnvDTE object
return visualStudio.dte();
view raw gistfile1.cs hosted with ❤ by GitHub

FluentSharp is an API that dramatically simplifies the use of .NET Framework APIs. It makes extensive use of .NET ExtensionMethods and it reduces the amount of code required (while making it more readable).

To use FluentSharp in your VisualStudio project you can use NuGet: http://nuget.org/packages?q=fluentSharp

For more information and script examples see:

Screnshots:

1) Menu created by installer:
2) C# REPL environment with FluentSharp VisualStudio API
3) Executing the Sample Script provided (2nd link from the REPL menu)
4) What VisualStudio looks like after executing the sample script