This is a mirror of official site: http://jasper-net.blogspot.com/

Dynamic ASP.NET MVC 3 models using Mono’s Compiler as a Service

| Thursday, June 16, 2011
5741600327_140bae7f06.jpg

I had an idea for an interactive MVC sample which will let you see the scaffolded editor and display for a model. I thought about a few ways to do this, the first being Mono’s compiler as a service. So far it’s a partial success – the model scaffolding works, but the attributes don’t (very possibly my mistake).

Getting the latest Mono Compiler
Miguel recommended that I grab the latest Mono build off Github, since there have been some improvements and bug fixes in the compiler. He wasn’t kidding, there’s a lot of active work going on in the compiler, and the Evaluator class (the main compiler service class) is no exception. Here’s the commit history just for the Evaluator (eval.cs):

A quick skim of the mcs (mono csharp compiler) commit messages in general shows a lot of work going on, including work on async: https://github.com/mono/mono/tree/master/mcs/mcs

The biggest change since the last Mono release, as Miguel blogged about in February, is the change from static API to an instance API:

…we turned the static API Evalutor.Eval (string expression), into an instance API. The instance API allows developers that are embedding the C# compiler-as-a-service in their application to have different contexts.

This required the entire compiler to be updated from being a giant set of static classes that could safely use global variables and state into a state that was properly encapsulated.

The API is now richer, we provide a way to configure the compiler settings using a settings class. This can be populated either manually, or by using the build-in command-line parser for compiler options.

This is good news – I find the new API easier to work with. The magical static stateful service API pattern works great for the REPL sample but causes problems if you’re doing anything much more complex. The downside, though, is that just about all the code samples and blog posts on the the Mono compiler service stuff don’t work as-is against the new compiler.

I didn’t want to set up a build environment for Mono. Fortunately, most established open source projects offer regular builds if you look around a bit. I grabbed the most recent MonoCharge package from http://mono.ximian.com/daily/, which includes all the precompiled binaries. They’re packaged as a .tar.gz, which opens up just fine in 7-zip. I just grabbed the Mono.CSharp.dll assembly.

Read more: Jon Galloway

Posted via email from Jasper-net

3 comments:

Anonymous said...

Heya i'm for the primary time here. I found this board and I in finding It really helpful & it helped me out much. I'm hoping to provide something back
and help others like you helped me.

my web blog - Michael Kors Canada

Anonymous said...

It's the best time to make a few plans for the long run and it is time to be happy. I've read
this submit and if I may I wish to counsel you few fascinating issues or suggestions.
Perhaps you could write next articles regarding this article.
I wish to learn even more issues about it!

Also visit my webpage :: Adfocus Auto Clicker

Anonymous said...

What's up to all, how is the whole thing, I think every one is getting more from this website, and your views are nice in favor of new viewers.

My homepage - Adfocus Auto Clicker