Exemple #1
0
        public void Compile(AstRoot root, Stream toStream, CompilationArguments arguments)
        {
            Argument.RequireNotNull("toStream", toStream);
            Argument.RequireNotNull("root", root);
            Argument.RequireNotNull("arguments", arguments);

            var assembly = AssemblyDefinition.CreateAssembly(
                new AssemblyNameDefinition(arguments.AssemblyName, arguments.AssemblyVersion),
                arguments.AssemblyName,
                arguments.Target == CompilationTarget.Console ? ModuleKind.Console : ModuleKind.Dll
                );

            var module  = assembly.MainModule;
            var context = new DefinitionBuildingContext(module, this.referenceProviders);

            foreach (var typeAst in root.Descendants <AstTypeDefinition>())
            {
                DefineType(module, typeAst, context);
            }
            context.ClearDebt();

            foreach (var type in module.Types)
            {
                foreach (var method in type.Methods)
                {
                    CompileMethod(method, context.GetAst(method), context);
                }
            }

            assembly.Write(toStream);
        }