Exemplo n.º 1
0
        private void AddColumnAttributes()
        {
            foreach (var propertyDeclaration in classDeclaration.PropertyDeclarations)
            {
                if (propertyDeclaration.HasAttribute(Constants.Column))
                {
                    continue;
                }

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

                var columnAttribute = CreateSchemaAttribute(Constants.Column);

                if (columnAttribute == null)
                {
                    return;
                }

                var columnName = propertyDeclaration.NameIdentifier.Name;

                var columnNameArgument = factory.CreateArgument(ParameterKind.VALUE, factory.CreateStringLiteralExpression($"{columnName}"));
                columnAttribute.AddArgumentBefore(columnNameArgument, null);

                var propertyType     = propertyDeclaration.Type;
                var typeNameArgument = factory.CreateArgument(ParameterKind.VALUE, factory.CreateExpression($"{Constants.TypeName} = $0", GetMappingTypeName(propertyType)));
                columnAttribute.AddArgumentBefore(typeNameArgument, null);

                propertyDeclaration.AddAttributeAfter(columnAttribute, propertyDeclaration.Attributes.LastOrDefault());

                AddAnnotationAttributesIfNeed(propertyDeclaration);
            }
        }
Exemplo n.º 2
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());
            }
        }