Example #1
0
        private NamespaceDeclarationSyntax GenerateCode(CollectMetadataSyntaxWalker metadataInfo, string ns)
        {
            var nameSpace = SyntaxTreeExtensions.NamespaceDeclaration(ns)     //SyntaxFactory.NamespaceDeclaration(SyntaxFactory.ParseName(ns)) //+-
                            .AddUsings("System.Xml.Serialization")
                            .AddUsings("System.Xml.Linq")
                            .AddUsings("System.Xml.Schema")
                            .AddUsings("System");

            //.AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("System.Xml.Serialization")));

            foreach (var serviceInterface in metadataInfo.Services)
            {
                var interfaceDeclarationSyntax = AddClientInterface(serviceInterface);
                nameSpace = nameSpace.AddMembers(interfaceDeclarationSyntax);

                var classDeclarationSyntax = AddClientImplementation(serviceInterface);
                nameSpace = nameSpace.AddMembers(classDeclarationSyntax);
            }

            foreach (var contractInfo in metadataInfo.Contracts)
            {
                var codeDeclaration = AddDataContract(contractInfo);
                nameSpace = nameSpace.AddMembers(codeDeclaration);
            }

            foreach (var enumInfo in metadataInfo.Enums)
            {
                var enumDeclSyntax = AddEnum(enumInfo);
                nameSpace = nameSpace.AddMembers(enumDeclSyntax);
            }

            return(nameSpace);
        }
Example #2
0
        private CollectMetadataSyntaxWalker ParseTree(SyntaxNode root, SemanticModel semanticModel)
        {
            var visitor = new CollectMetadataSyntaxWalker(semanticModel);

            visitor.Visit(root);

            return(visitor);
        }