コード例 #1
0
        private PropertyDeclarationSyntax CreatePropertyImpl(TypeSyntax type, SymbolData symbol)
        {
            // public [type] [symbol.Name] { get; set; }
            var node = SF.PropertyDeclaration(type, symbol.Name)
                       .AddModifiers(SF.Token(SyntaxKind.PublicKeyword))
                       .AddAccessorListAccessors(
                SF.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                .WithSemicolonToken(SF.Token(SyntaxKind.SemicolonToken)),
                SF.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
                .WithSemicolonToken(SF.Token(SyntaxKind.SemicolonToken)));

            if (_options.IsJsonSerializable)
            {
                node = node.WithAttributeLists(CreateSerializationAttribute(symbol));
            }

            if (!string.IsNullOrEmpty(symbol.Summary))
            {
                var comment = new DocumentComment()
                {
                    Summary = symbol.Summary
                };
                node = node.WithLeadingTrivia(comment.ConstructTriviaList());
            }

            return(node);
        }
コード例 #2
0
        private ClassDeclarationSyntax CreateClass(SymbolData symbol)
        {
            var className = symbol.Name.ToClassName();
            var node      = SF.ClassDeclaration(className)
                            .AddModifiers(SF.Token(SyntaxKind.PublicKeyword));

            if (_options.IsJsonSerializable)
            {
                node = node.WithAttributeLists(
                    SF.SingletonList(
                        SF.AttributeList(
                            SF.SingletonSeparatedList(
                                SF.Attribute(SF.IdentifierName("JsonObject"))))));
            }

            if (!string.IsNullOrEmpty(symbol.Summary))
            {
                var comment = new DocumentComment()
                {
                    Summary = symbol.Summary
                };
                node = node.WithLeadingTrivia(comment.ConstructTriviaList());
            }

            var props = new List <MemberDeclarationSyntax>();

            foreach (var member in symbol.Members)
            {
                props.Add(ConstructImpl(member) as MemberDeclarationSyntax);
                if (member.TypeName == "object")
                {
                    var childSymbol = member.CreateInstanceSymbol();
                    props.Add(CreateProperty(childSymbol));
                }
            }
            return(node.AddMembers(props.ToArray()));
        }