Пример #1
0
 public static ValidationAttribute[] GetValidationAttributes(this ObjectExtensionPropertyInfo propertyInfo)
 {
     return(propertyInfo
            .Attributes
            .OfType <ValidationAttribute>()
            .ToArray());
 }
Пример #2
0
        private static void AddPropertyValidationAttributeErrors(
            IHasExtraProperties extensibleObject,
            List <ValidationResult> validationErrors,
            ValidationContext objectValidationContext,
            ObjectExtensionPropertyInfo property)
        {
            if (!property.ValidationAttributes.Any())
            {
                return;
            }

            var propertyValidationContext = new ValidationContext(extensibleObject, objectValidationContext, null)
            {
                DisplayName = property.Name,
                MemberName  = property.Name
            };

            foreach (var attribute in property.ValidationAttributes)
            {
                var result = attribute.GetValidationResult(
                    extensibleObject.GetProperty(property.Name),
                    propertyValidationContext
                    );

                if (result != null)
                {
                    validationErrors.Add(result);
                }
            }
        }
Пример #3
0
        private static void ExecuteCustomPropertyValidationActions(
            IHasExtraProperties extensibleObject,
            List <ValidationResult> validationErrors,
            ValidationContext objectValidationContext,
            ObjectExtensionPropertyInfo property,
            object value)
        {
            if (!property.Validators.Any())
            {
                return;
            }

            var context = new ObjectExtensionPropertyValidationContext(
                property,
                extensibleObject,
                validationErrors,
                objectValidationContext,
                value
                );

            foreach (var validator in property.Validators)
            {
                validator(context);
            }
        }
        public ObjectExtensionPropertyInfoEfCoreMappingOptions(
            [NotNull] ObjectExtensionPropertyInfo extensionProperty,
            [CanBeNull] Action <PropertyBuilder> propertyBuildAction = null)
        {
            ExtensionProperty = Check.NotNull(extensionProperty, nameof(extensionProperty));

            PropertyBuildAction = propertyBuildAction;
        }
        public ObjectExtensionPropertyInfoEfCoreMappingOptions(
            [NotNull] ObjectExtensionPropertyInfo extensionProperty,
            [CanBeNull] Action <EntityTypeBuilder, PropertyBuilder> entityTypeAndPropertyBuildAction)
        {
            ExtensionProperty = Check.NotNull(extensionProperty, nameof(extensionProperty));

            EntityTypeAndPropertyBuildAction = entityTypeAndPropertyBuildAction;
        }
        public static bool IsMappedToFieldForEfCore(
            [NotNull] this ObjectExtensionPropertyInfo propertyExtension)
        {
            Check.NotNull(propertyExtension, nameof(propertyExtension));

            return(propertyExtension
                   .Configuration
                   .ContainsKey(EfCorePropertyConfigurationName));
        }
        public static ObjectExtensionPropertyInfoEfCoreMappingOptions GetEfCoreMappingOrNull(
            [NotNull] this ObjectExtensionPropertyInfo propertyExtension)
        {
            Check.NotNull(propertyExtension, nameof(propertyExtension));

            return(propertyExtension
                   .Configuration
                   .GetOrDefault(EfCorePropertyConfigurationName)
                   as ObjectExtensionPropertyInfoEfCoreMappingOptions);
        }
        public static ObjectExtensionPropertyInfo MapEfCore(
            [NotNull] this ObjectExtensionPropertyInfo propertyExtension)
        {
            Check.NotNull(propertyExtension, nameof(propertyExtension));

            propertyExtension.Configuration[EfCorePropertyConfigurationName] =
                new ObjectExtensionPropertyInfoEfCoreMappingOptions(
                    propertyExtension
                    );

            return(propertyExtension);
        }
Пример #9
0
 public ObjectExtensionPropertyValidationContext(
     [NotNull] ObjectExtensionPropertyInfo objectExtensionPropertyInfo,
     [NotNull] IHasExtraProperties validatingObject,
     [NotNull] List <ValidationResult> validationErrors,
     [NotNull] ValidationContext validationContext,
     [CanBeNull] object value)
 {
     ExtensionPropertyInfo = Check.NotNull(objectExtensionPropertyInfo, nameof(objectExtensionPropertyInfo));
     ValidatingObject      = Check.NotNull(validatingObject, nameof(validatingObject));
     ValidationErrors      = Check.NotNull(validationErrors, nameof(validationErrors));
     ValidationContext     = Check.NotNull(validationContext, nameof(validationContext));
     Value = value;
 }
Пример #10
0
        public static string GetInputType(this ObjectExtensionPropertyInfo propertyInfo)
        {
            foreach (var attribute in propertyInfo.Attributes)
            {
                var inputTypeByAttribute = GetInputTypeFromAttributeOrNull(attribute);
                if (inputTypeByAttribute != null)
                {
                    return(inputTypeByAttribute);
                }
            }

            return(GetInputTypeFromTypeOrNull(propertyInfo.Type)
                   ?? "text"); //default
        }
        public static ObjectExtensionPropertyInfo MapEfCore(
            [NotNull] this ObjectExtensionPropertyInfo propertyExtension,
            [CanBeNull] Action <EntityTypeBuilder, PropertyBuilder> entityTypeAndPropertyBuildAction)
        {
            Check.NotNull(propertyExtension, nameof(propertyExtension));

            propertyExtension.Configuration[EfCorePropertyConfigurationName] =
                new ObjectExtensionPropertyInfoEfCoreMappingOptions(
                    propertyExtension,
                    entityTypeAndPropertyBuildAction: entityTypeAndPropertyBuildAction
                    );

            return(propertyExtension);
        }
Пример #12
0
        private static void AddPropertyValidationErrors(
            IHasExtraProperties extensibleObject,
            List <ValidationResult> validationErrors,
            ValidationContext objectValidationContext,
            ObjectExtensionPropertyInfo property)
        {
            AddPropertyValidationAttributeErrors(
                extensibleObject,
                validationErrors,
                objectValidationContext,
                property
                );

            ExecuteCustomPropertyValidationActions(
                extensibleObject,
                validationErrors,
                objectValidationContext,
                property
                );
        }
 public ObjectExtensionPropertyInfoEfCoreMappingOptions(
     [NotNull] ObjectExtensionPropertyInfo extensionProperty)
 {
     ExtensionProperty = Check.NotNull(extensionProperty, nameof(extensionProperty));
 }