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