Пример #1
0
        private static SyntaxNode TransformHeaderModel(RootModel root, Func <MockIdentGrammarModel, Scope, SyntaxNode> parse, Scope scope)
        {
            var statements = new List <StatementSyntax>();

            foreach (var header in root.Headers)
            {
                foreach (var value in header.Values)
                {
                    statements.Add(HeaderValue.Get <StatementSyntax>(
                                       RoslynCompiler.Quoted(header.Name),
                                       RoslynCompiler.Quoted(value.Left.ToString()),
                                       value.Right));
                }

                foreach (var contact in header.Contacts)
                {
                    statements.Add(Contact.Get <StatementSyntax>(
                                       RoslynCompiler.Quoted(header.Name),
                                       RoslynCompiler.Quoted(contact.Name),
                                       RoslynCompiler.Quoted(contact.Telephone)));

                    foreach (var phone in contact.OtherNumbers)
                    {
                        statements.Add(OtherNumber.Get <StatementSyntax>(
                                           RoslynCompiler.Quoted(header.Name),
                                           RoslynCompiler.Quoted(contact.Name),
                                           CSharp.LiteralExpression(
                                               SyntaxKind.NumericLiteralExpression,
                                               CSharp.Literal(phone.AreaCode)),
                                           CSharp.LiteralExpression(
                                               SyntaxKind.NumericLiteralExpression,
                                               CSharp.Literal(phone.FirstThree)),
                                           CSharp.LiteralExpression(
                                               SyntaxKind.NumericLiteralExpression,
                                               CSharp.Literal(phone.LastFour))));
                    }
                }

                if (header.Location != null)
                {
                    statements.Add(Location.Get <StatementSyntax>(
                                       RoslynCompiler.Quoted(header.Name),
                                       RoslynCompiler.Quoted(header.Location.Place ?? ""),
                                       RoslynCompiler.Quoted(header.Location.City ?? "")));
                }
            }

            foreach (var forStatement in root.Statements)
            {
                statements.Add(CSharp
                               .ForEachStatement(
                                   CSharp.ParseTypeName("var"),
                                   forStatement.Iterator,
                                   CSharp.ParseExpression(forStatement.Iterable),
                                   CSharp.Block(forStatement
                                                .Statements
                                                .ToArray())));
            }

            return(CSharp.Block(statements.ToArray()));
        }