Microsoft has been pretty secret with its products up until the recent years. I can say that in the past couple of years Microsoft has made big steps in the direction of open source.

One of its best and recent initiatives is the Roslyn open-source compilers which are be promised to come with the new version of Visual Studio 2014. I’d say that this is a huge improvement but you may wonder what this really means for the developers.
Well, aside from the fact that they’re open source and you can actually look into the code of the C# compiler there are a lot of more implications.
First of all, this opens the door to the a new era of C# scripting because as of now Roslyn allows you to actually write, compile and run C# code within an application that’s already running, that’s impressive.
Of course there are innovations in the area of refactoring and code analysis but that’s just the beginning of this powerful change. Roslyn also open the door to other open source initiatives such as Mono but let’s see where it goes.

Roslyn is in CTP now and there are things that are still subject to change but what is to come is really interesting.

I will soon post some code snippets 🙂

 

Either way I am excited!

More info here: Roslyn
[spoiler title=”C# code snippets of Roslyn scripting”]

_context = context;
_engine = new ScriptEngine();
ScriptEngineLoadAssemblies(_engine, context.GetType().Assembly.Location);
_currentModule = context.GetType().ToString();
Session = _engine.CreateSession(context, context.GetType());
private void LoadAssemblies()
{
try
{
//with _session.Execute("code"); you can execute any C# code you want
_session.Execute(
"using System;using System.ComponentModel;" +
"using System.ComponentModel.Composition;" +
"using System.IO;using System.Linq;" +
"using System.Runtime.Serialization;" +
"using System.ServiceModel;" +
"using System.Windows;");
}
catch (Exception e)
{

}

}

public void ScriptEngineLoadAssemblies(ScriptEngine engine, string localAssembly)
{
//GAC Assemblies
var systemCoreReference = MetadataReference.CreateAssemblyReference("System.Core");
var systemReference = MetadataReference.CreateAssemblyReference("System");
var systemComponentModel = MetadataReference.CreateAssemblyReference("System.ComponentModel");
var systemComponentModelComposition =
MetadataReference.CreateAssemblyReference("System.ComponentModel.Composition");
var systemIO = MetadataReference.CreateAssemblyReference("System.IO");
var systemLinq = MetadataReference.CreateAssemblyReference("System.Linq");
var systemReflection = MetadataReference.CreateAssemblyReference("System.Runtime.Serialization");
var systemServiceModel = MetadataReference.CreateAssemblyReference("System.ServiceModel");
var systemWindows = MetadataReference.CreateAssemblyReference("System.Windows");

//Custom Assemblies

engine.AddReference(systemCoreReference);
engine.AddReference(systemReference);
engine.AddReference(systemComponentModel);
engine.AddReference(systemComponentModelComposition);
engine.AddReference(systemIO);
engine.AddReference(systemLinq);
engine.AddReference(systemReflection);
engine.AddReference(systemServiceModel);
engine.AddReference(systemWindows);
engine.AddReference(localAssembly);

}

Basically you need the scriptengine, a session and a context where the code is executed.
[/spoiler]

Simple Share Buttons