Exemple #1
0
        private SyntaxNode GenerateDtoNode(DtoDefinition definition)
        {
            var classDeclaration = ClassDeclaration(definition.Name)
                                   .WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword)))
                                   .WithMembers(List(definition.Properties.Select(GeneratePropertyFromDtoDefinition)));

            var namespaceDeclaration = NamespaceDeclaration((NameSyntax)ParseTypeName(_namespaceName))
                                       .WithMembers(SingletonList <MemberDeclarationSyntax>(classDeclaration));

            return(CompilationUnit()
                   .WithUsings(List(definition.RequestedNamespaces.Select(ToUsingDirective)))
                   .WithMembers(SingletonList <MemberDeclarationSyntax>(namespaceDeclaration)));
        }
Exemple #2
0
        public static DtoDefinition ParseDefinition(JsonProperty jsonDefinition)
        {
            var dtoProperties = jsonDefinition
                                .Value
                                .GetProperty("properties")
                                .EnumerateObject()
                                .Select(ToPropertyDefinition);

            var dtoDefinition = new DtoDefinition
            {
                Name       = jsonDefinition.Name,
                Properties = dtoProperties
            };

            return(dtoDefinition);
        }
Exemple #3
0
        public void EmitDto(DtoDefinition definition)
        {
            var root = GenerateDtoNode(definition);

            EmitSource(root, $"{definition.Name}.cs");
        }