Example #1
0
        private void AddJsonPropertyAttributes()
        {
            foreach (var propertyDeclaration in classDeclaration.PropertyDeclarations)
            {
                if (propertyDeclaration.HasAttribute(Constants.JsonProperty))
                {
                    continue;
                }

                if (!propertyDeclaration.HasGetSet())
                {
                    continue;
                }

                var attribute = provider.CreateAttribute($"Newtonsoft.Json.{Constants.JsonProperty}Attribute");

                if (attribute == null)
                {
                    return;
                }

                var propertyName = propertyDeclaration.NameIdentifier.Name;

                var propertyNameArgument = factory.CreateArgument(ParameterKind.VALUE, factory.CreateStringLiteralExpression($"{propertyNameTransform(propertyName)}"));
                attribute.AddArgumentBefore(propertyNameArgument, null);
                propertyDeclaration.AddAttributeAfter(attribute, propertyDeclaration.Attributes.LastOrDefault());
            }
        }
Example #2
0
 private IAttribute CreateSchemaAttribute(string attributeShortTypeName) => provider.CreateAttribute($"System.ComponentModel.DataAnnotations.Schema.{attributeShortTypeName}Attribute");