Roslyn, deux qui la tiennent...

Roslyn September CTP is out, despite rumors of it  being dead, and although there is no redist, it solves all the issues I had with type dependency (Mono's terrible API really does not help) and opens-up the road for VS.Net integration.

This is very exiting news for C#ylon!

using Roslyn.Compilers;
using Roslyn.Compilers.CSharp;

namespace RoslynTest
{
    class Program
    {
        static void Main(string[] args)
        {

            var comp = Compilation.Create("Test.dll"
                , syntaxTrees: new[] { CreateTree("Foo", "Bar"), CreateTree("Bar", "Foo") }
                , references: new[] { new MetadataFileReference("mscorlib.dll") }
                                   , options: new CompilationOptions(OutputKind.DynamicallyLinkedLibrary)
                );

            EmitResult a = comp.Emit("Test.dll");
        }

        private static SyntaxTree CreateTree(string a, string b)
        {
            return SyntaxTree.Create(Syntax.CompilationUnit()
                                         .WithUsings(Syntax.UsingDirective(Syntax.ParseName("System")))
                                         .WithMembers(Syntax.List(CreateCoDep(a, b))));
        }

        private static MemberDeclarationSyntax CreateCoDep(string typeName, string fieldName)
        {
            return Syntax.ClassDeclaration(typeName)
                .WithMembers(
                    (Syntax.FieldDeclaration(Syntax.VariableDeclaration(Syntax.ParseTypeName(fieldName))
                .WithVariables(Syntax.SeparatedList(Syntax.VariableDeclarator(fieldName))))));
        }
    }
}


Back to hacking  tonight!