コード例 #1
0
        public static ClassDeclarationSyntax Create(IClass element)
        {
            var modifierDeclaration = SyntaxFactory.ParseToken(element.ModifierDeclaration);
            var classDeclaration    = SyntaxFactory.ClassDeclaration(element.Name).AddModifiers(modifierDeclaration);

            if (element.Attributes?.Any() ?? false)
            {
                classDeclaration = classDeclaration.AddAttributeLists(element.Attributes.Select(item => ConstructAttribute.Create(item)).ToArray());
            }

            return(classDeclaration);
        }
コード例 #2
0
        public static PropertyDeclarationSyntax Create(IProperty element)
        {
            var propertyDeclaration = SyntaxFactory.PropertyDeclaration(SyntaxFactory.ParseTypeName(element.Type), element.Name)
                                      .AddModifiers(SyntaxFactory.ParseToken(element.ModifierDeclaration));

            if (element.SetAccessor)
            {
                propertyDeclaration = propertyDeclaration.AddAccessorListAccessors(SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)));
            }

            if (element.GetAccessor)
            {
                propertyDeclaration = propertyDeclaration.AddAccessorListAccessors(SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)));
            }

            if (element.Attributes?.Any() ?? false)
            {
                propertyDeclaration = propertyDeclaration.AddAttributeLists(element.Attributes.Select(item => ConstructAttribute.Create(item)).ToArray());
            }

            return(propertyDeclaration);
        }