public static PropertyDeclarationSyntax AddFromFormAttribute(
        this PropertyDeclarationSyntax propertyDeclaration)
    {
        ArgumentNullException.ThrowIfNull(propertyDeclaration);

        return(propertyDeclaration.AddAttributeLists(SyntaxAttributeListFactory.Create(nameof(FromFormAttribute))));
    }
Пример #2
0
 private static PropertyDeclarationSyntax DecorateWithKeyAttribute(PropertyDeclarationSyntax publicProperty)
 {
     return(publicProperty.AddAttributeLists(SyntaxFactory.AttributeList(
                                                 SyntaxFactory.SingletonSeparatedList(
                                                     SyntaxFactory.Attribute(SyntaxFactory.IdentifierName("Key"))
                                                     )
                                                 )));
 }
Пример #3
0
 public static PropertyDeclarationSyntax AddDataMemberAttribute(this PropertyDeclarationSyntax prop)
 {
     return(prop.AddAttributeLists(new[]
     {
         SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(
                                         SyntaxFactory.Attribute(SyntaxFactory.IdentifierName(Constants.Attribute.DataMember))))
     }));
 }
        public static PropertyDeclarationSyntax AddFromBodyAttribute(this PropertyDeclarationSyntax propertyDeclaration)
        {
            if (propertyDeclaration == null)
            {
                throw new ArgumentNullException(nameof(propertyDeclaration));
            }

            return(propertyDeclaration.AddAttributeLists(SyntaxAttributeListFactory.Create(nameof(FromBodyAttribute))));
        }
Пример #5
0
 public MemberSyntax(PropertyDeclarationSyntax prop)
 {
     this.AttributeLists       = prop.AttributeLists;
     this.GetLeadingTrivia     = () => prop.GetLeadingTrivia();
     this.ReplaceNode          = (x, y) => prop.ReplaceNode(x, y);
     this.WithoutLeadingTrivia = () => new MemberSyntax(prop.WithoutLeadingTrivia());
     this.WithLeadingTrivia    = x => new MemberSyntax(prop.WithLeadingTrivia(x));
     this.AddAttributeLists    = xs => new MemberSyntax(prop.AddAttributeLists(xs));
     this.Self = prop;
 }
        private static PropertyDeclarationSyntax AddAttribute(PropertyDeclarationSyntax property, string attributeName)
        {
            var newAttributes = SyntaxFactory.AttributeList(
                SyntaxFactory.SingletonSeparatedList(
                    SyntaxFactory.Attribute(SyntaxFactory.IdentifierName(attributeName))
                    )
                );

            property = property.AddAttributeLists(newAttributes);
            return(property);
        }
    public static PropertyDeclarationSyntax AddValidationAttribute(
        this PropertyDeclarationSyntax propertyDeclaration,
        ValidationAttribute validationAttribute)
    {
        ArgumentNullException.ThrowIfNull(propertyDeclaration);
        ArgumentNullException.ThrowIfNull(validationAttribute);

        return(propertyDeclaration.AddAttributeLists(
                   SyntaxFactory.AttributeList(
                       SyntaxFactory.SingletonSeparatedList(
                           SyntaxAttributeFactory.CreateFromValidationAttribute(validationAttribute)))));
    }
    public static PropertyDeclarationSyntax AddFromHeaderAttribute(
        this PropertyDeclarationSyntax propertyDeclaration,
        string nameProperty,
        OpenApiSchema schema)
    {
        ArgumentNullException.ThrowIfNull(propertyDeclaration);
        ArgumentNullException.ThrowIfNull(nameProperty);

        return(propertyDeclaration.AddAttributeLists(
                   SyntaxAttributeListFactory.CreateWithOneItemWithOneArgumentWithNameEquals(
                       nameof(FromHeaderAttribute),
                       nameof(FromHeaderAttribute.Name),
                       nameProperty))
               .AddValidationAttributeFromSchemaFormatIfRequired(schema));
    }
        private PropertyDeclarationSyntax EnsureAttribute(PropertyDeclarationSyntax property, AttributeSyntax attributeSyntax)
        {
            var attributeName = GetSimpleNameFromNode(attributeSyntax).Identifier.ValueText;

            if (HasAttribute(property.AttributeLists, attributeName))
            {
                property = RemoveAttribute(property, attributeName);
            }

            var newAttributes = SyntaxFactory.AttributeList(
                SyntaxFactory.SingletonSeparatedList(attributeSyntax)
                );

            property = property.AddAttributeLists(newAttributes);
            return(property);
        }
Пример #10
0
        public override SyntaxNode VisitPropertyDeclaration(PropertyDeclarationSyntax node)
        {
            if (this.propsToDecorate.Contains(node))
            {
                var name = node.Identifier.ValueText;

                //// OF COURSE there must be a verification that there is no such attribute already.
                var changedProp = node.AddAttributeLists(
                    SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList <AttributeSyntax>(
                                                    SyntaxFactory.Attribute(
                                                        SyntaxFactory.IdentifierName("DisplayName"),
                                                        SyntaxFactory.AttributeArgumentList(SyntaxFactory.SingletonSeparatedList <AttributeArgumentSyntax>(SyntaxFactory.AttributeArgument(SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal($"{name}_Decorated")))))))));
                return(base.VisitPropertyDeclaration(changedProp));
            }

            return(base.VisitPropertyDeclaration(node));
        }
        public static PropertyDeclarationSyntax AddValidationAttribute(this PropertyDeclarationSyntax propertyDeclaration, ValidationAttribute validationAttribute)
        {
            if (propertyDeclaration == null)
            {
                throw new ArgumentNullException(nameof(propertyDeclaration));
            }

            if (validationAttribute == null)
            {
                throw new ArgumentNullException(nameof(validationAttribute));
            }

            return(propertyDeclaration.AddAttributeLists(
                       SyntaxFactory.AttributeList(
                           SyntaxFactory.SingletonSeparatedList(
                               SyntaxAttributeFactory.CreateFromValidationAttribute(validationAttribute)))));
        }
        public static PropertyDeclarationSyntax AddFromQueryAttribute(this PropertyDeclarationSyntax propertyDeclaration, string nameProperty, OpenApiSchema schema)
        {
            if (propertyDeclaration == null)
            {
                throw new ArgumentNullException(nameof(propertyDeclaration));
            }

            if (nameProperty == null)
            {
                throw new ArgumentNullException(nameof(nameProperty));
            }

            return(propertyDeclaration.AddAttributeLists(
                       SyntaxAttributeListFactory.CreateWithOneItemWithOneArgumentWithNameEquals(
                           nameof(FromQueryAttribute),
                           nameof(FromQueryAttribute.Name),
                           nameProperty))
                   .AddValidationAttributeFromSchemaFormatIfRequired(schema));
        }
Пример #13
0
        /// <summary>
        /// Create a property declaration.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property.
        /// </param>
        /// <returns>
        /// A property declaration built from the specified schema.
        /// </returns>
        private PropertyDeclarationSyntax CreatePropertyDeclaration(string propertyName)
        {
            PropertyInfo info = PropInfoDictionary[propertyName];

            PropertyDeclarationSyntax propDecl = SyntaxFactory.PropertyDeclaration(
                info.Type,
                propertyName.ToPascalCase())
                                                 .AddModifiers(GenerateSchemaPropertyModifiers(propertyName))
                                                 .AddAccessorListAccessors(GeneratePropertyAccessors());

            AttributeSyntax[] attributes = GeneratePropertyAttributes(propertyName, info.SerializedName, info.IsRequired, info.DefaultValue, info.Type);
            if (attributes.Length > 0)
            {
                propDecl = propDecl.AddAttributeLists(attributes
                                                      .Select(attr => SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(attr)))
                                                      .ToArray());
            }

            return(propDecl.WithLeadingTrivia(
                       SyntaxHelper.MakeDocComment(info.Description)));
        }
Пример #14
0
        public static PropertyDeclarationSyntax AddJsonPropertyAttribute(this PropertyDeclarationSyntax prop)
        {
            var propName = prop.Identifier.ValueText;

            return(prop.AddAttributeLists(new[]
            {
                SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(
                                                SyntaxFactory.Attribute(SyntaxFactory.IdentifierName(Constants.Attribute.JsonProperty))
                                                .WithArgumentList(
                                                    SyntaxFactory.AttributeArgumentList(
                                                        SyntaxFactory.SingletonSeparatedList(
                                                            SyntaxFactory.AttributeArgument(
                                                                SyntaxFactory.LiteralExpression(
                                                                    SyntaxKind.StringLiteralExpression,
                                                                    SyntaxFactory.Literal(propName.ToLowerCamelCase())
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
            }));
        }
Пример #15
0
        public static PropertyDeclarationSyntax AddNeo4JRelationshipAttribute(
            this PropertyDeclarationSyntax methodSyntax,
            string name,
            RelationshipDirection direction)
        {
            AttributeSyntax attribute =
                Attribute(IdentifierName(Global(Neo4JRelationshipAttribute)))
                .AddArgumentListArguments(
                    AttributeArgument(
                        LiteralExpression(
                            SyntaxKind.NumericLiteralExpression,
                            Literal(name)))
                    .WithNameColon(
                        NameColon(IdentifierName(nameof(name)))),
                    AttributeArgument(
                        MemberAccessExpression(
                            SyntaxKind.SimpleMemberAccessExpression,
                            IdentifierName(Global(Neo4JRelationshipDirection)),
                            IdentifierName(MapDirection(direction))))
                    .WithNameColon(
                        NameColon(IdentifierName(nameof(direction)))));

            return(methodSyntax.AddAttributeLists(AttributeList(SingletonSeparatedList(attribute))));
        }
Пример #16
0
 public static PropertyDeclarationSyntax AddAttributeLists(this PropertyDeclarationSyntax syntax, IEnumerable <AttributeListSyntax> lists)
 {
     return(syntax.AddAttributeLists(lists.ToArray()));
 }
Пример #17
0
 public static PropertyDeclarationSyntax AddAttributeListAttribute(this PropertyDeclarationSyntax syntax, AttributeSyntax attribute)
 {
     return(syntax.AddAttributeLists(AttributeList(SingletonSeparatedList(attribute))));
 }
Пример #18
0
 public static PropertyDeclarationSyntax WithGeneratedAttribute(this PropertyDeclarationSyntax node)
 => node.AddAttributeLists(AttributeList(SingletonSeparatedList(CreateGeneratedCodeAttribute())));
Пример #19
0
 public static PropertyDeclarationSyntax AddAttribute(this PropertyDeclarationSyntax source, AttributeSyntax attributes)
 {
     return(source.AddAttributeLists(AttributeList(SingletonSeparatedList(attributes))));
 }
Пример #20
0
 public static PropertyDeclarationSyntax AddAttributes(this PropertyDeclarationSyntax source, params AttributeSyntax[] attributes)
 {
     return(source.AddAttributeLists(AttributeList(SeparatedList(attributes))));
 }
Пример #21
0
 public static PropertyDeclarationSyntax WithAttributes(this PropertyDeclarationSyntax node, params AttributeSyntax[] attributes)
 {
     return(node.AddAttributeLists(AttributeList(SeparatedList(attributes))));
 }
Пример #22
0
        public static PropertyDeclarationSyntax AddAttribute(this PropertyDeclarationSyntax propertyDeclarationSyntax, AttributeSyntax attributeSyntax)
        {
            var attributeList = SyntaxFactory.AttributeList().AddAttributes(attributeSyntax);

            return(propertyDeclarationSyntax.AddAttributeLists(attributeList));
        }