Beispiel #1
0
        public static Assembly Compile(CompilationUnitNode ast)
        {
            var errors = ast.Validate();

            errors.Count.Should().Be(0, errors.FirstOrDefault()?.ErrorMessage);
            var code = CSharpTranspileVisitor.ToString(ast);

            Debug.WriteLine(code);
            var testAssemblyName = GetTestAssemblyName();

            return(Compile(code, testAssemblyName));
        }
Beispiel #2
0
        public static Assembly Compile(ClassNode ast)
        {
            var testAssemblyName = GetTestAssemblyName();
            var unit             = new CompilationUnitNode
            {
                Members = new ListNode <AstNode>
                {
                    new NamespaceNode
                    {
                        Name         = new DottedIdentifierNode(testAssemblyName),
                        Declarations = new ListNode <AstNode>
                        {
                            ast
                        }
                    }
                }
            };
            var errors = unit.Validate();

            errors.Count.Should().Be(0);
            var code = CSharpTranspileVisitor.ToString(unit);

            return(Compile(code, testAssemblyName));
        }