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))); }
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); }
public void EmitDto(DtoDefinition definition) { var root = GenerateDtoNode(definition); EmitSource(root, $"{definition.Name}.cs"); }