Esempio n. 1
0
        public object Render()
        {
            AssociationView derivedBaseProperty = Property.DerivedBaseProperty();

            var derivedName = derivedBaseProperty != null
                ? derivedBaseProperty.OtherEntity.Name
                : null;

            var desc = this[ResourceRenderer.DescriptionOverride] != null
                ? this[ResourceRenderer.DescriptionOverride]
                       .ScrubForXmlDocumentation()
                : UniqueIdSpecification.IsUniqueId(Property.PropertyName)
                    ? string.Format(
                "A unique alphanumeric code assigned to a {0}.",
                Property.RemoveUniqueIdOrUsiFromPropertyName()
                .ToLower())
                    : Property.Description.ScrubForXmlDocumentation();

            var propertyNamespacePrefix = Property.ProperCaseSchemaName() == null
                ? null
                : $"{Namespaces.Entities.Common.RelativeNamespace}.{Property.ProperCaseSchemaName()}.";

            return(new
            {
                Description = desc,
                Misc = this[ResourceRenderer.MiscellaneousComment],
                JsonPropertyName = Property.JsonPropertyName,
                PropertyName = IsReferencedProperty
                    ? string.Format(
                    "backReference.{0} != null && backReference.{0}.{1}",
                    Property.EntityProperty.Entity.Aggregate.Name,
                    Property.PropertyName)
                    : Property.PropertyName,
                CSharpSafePropertyName = Property.PropertyName.MakeSafeForCSharpClass(Property.ParentFullName.Name),
                ParentName =
                    Property.EntityProperty.IsFromParent
                        ? Property.EntityProperty.Entity.Parent.Name
                        : Property.EntityProperty.Entity.Name,
                PropertyFieldName = Property.EntityProperty.Entity
                                    .ResolvedEdFiEntityName()
                                    .ToCamelCase(),
                PropertyType = Property.PropertyType.ToCSharp(true),
                IsFirstProperty = IsFirstProperty,
                IsLastProperty = IsLastProperty,
                IsUnique = IsUnique,
                NumericAttribute = Property.ToRangeAttributeCSharp(),
                IsDateOnlyProperty = Property.PropertyType.DbType == DbType.Date,
                IsTimeSpanProperty = Property.PropertyType.DbType == DbType.Time,
                ClassName = this[ResourceRenderer.ClassName]
                            ?? Property.EntityProperty.Entity
                            .ResolvedEdFiEntityName(),
                UnifiedKeys = Associations.Any()
                    ? AssembleOtherUnifiedChild(Associations)
                    : null,
                UnifiedExtensions = ExtensionAssociations.Any()
                    ? AssembleOtherUnifiedChild(ExtensionAssociations)
                    : null,
                ImplicitPropertyName = Associations.Any()
                    ? Associations.OrderByDescending(x => x.IsRequired)
                                       .First()
                                       .Name
                    : null,
                ImplicitNullable = Property.PropertyType.IsNullableCSharpType()
                    ? ".GetValueOrDefault()"
                    : null,
                ParentPropertyName = this[ResourceRenderer.ParentPropertyName],
                DerivedName = derivedName,
                PropertyNamespacePrefix = propertyNamespacePrefix,
                NullPropertyPrefix = Property.EntityProperty.Entity.IsEntityExtension
                    ? $"{propertyNamespacePrefix}I{Property.EntityProperty.Entity.Name}."
                    : $"{propertyNamespacePrefix}I{Property.EntityProperty.Entity.ResolvedEdFiEntityName()}."
            });
        }