public ObjectExtensionValidationContext(
     [NotNull] ObjectExtensionInfo objectExtensionInfo, [NotNull] IHasExtraProperties validatingObject, [NotNull] List <ValidationResult> validationErrors, [NotNull] ValidationContext validationContext)
 {
     ObjectExtensionInfo = Check.NotNull(objectExtensionInfo, nameof(objectExtensionInfo));
     ValidatingObject    = Check.NotNull(validatingObject, nameof(validatingObject));
     ValidationErrors    = Check.NotNull(validationErrors, nameof(validationErrors));
     ValidationContext   = Check.NotNull(validationContext, nameof(validationContext));
 }
Ejemplo n.º 2
0
 public static ObjectExtensionInfo MapEfCoreProperty <TProperty> (
     [NotNull] this ObjectExtensionInfo objectExtensionInfo, [NotNull] string propertyName, [CanBeNull] Action <PropertyBuilder> propertyBuildAction)
 {
     return(objectExtensionInfo.MapEfCoreProperty(
                typeof(TProperty),
                propertyName,
                propertyBuildAction
                ));
 }
Ejemplo n.º 3
0
        public ObjectExtensionPropertyInfo(
            [NotNull] ObjectExtensionInfo objectExtension, [NotNull] Type type, [NotNull] string name)
        {
            ObjectExtension = Check.NotNull(objectExtension, nameof(objectExtension));
            Type            = Check.NotNull(type, nameof(type));
            Name            = Check.NotNull(name, nameof(name));

            Configuration = new Dictionary <object, object> ();
            // ValidationAttributes = new List<ValidationAttribute> ();
            Attributes = new List <Attribute> ();
            Validators = new List <Action <ObjectExtensionPropertyValidationContext> > ();
        }
Ejemplo n.º 4
0
        public static ObjectExtensionInfo MapEfCoreProperty(
            [NotNull] this ObjectExtensionInfo objectExtensionInfo, [NotNull] Type propertyType, [NotNull] string propertyName, [CanBeNull] Action <PropertyBuilder> propertyBuildAction)
        {
            Check.NotNull(objectExtensionInfo, nameof(objectExtensionInfo));

            return(objectExtensionInfo.AddOrUpdateProperty(
                       propertyType,
                       propertyName,
                       options => {
                options.MapEfCore(
                    propertyBuildAction
                    );
            }
                       ));
        }
Ejemplo n.º 5
0
        private static void ExecuteCustomObjectValidationActions(
            IHasExtraProperties extensibleObject,
            List <ValidationResult> validationErrors,
            ValidationContext objectValidationContext,
            ObjectExtensionInfo objectExtensionInfo)
        {
            if (!objectExtensionInfo.Validators.Any())
            {
                return;
            }

            var context = new ObjectExtensionValidationContext(
                objectExtensionInfo,
                extensibleObject,
                validationErrors,
                objectValidationContext
                );

            foreach (var validator in objectExtensionInfo.Validators)
            {
                validator(context);
            }
        }
Ejemplo n.º 6
0
        private static void AddPropertyValidationErrors(
            IHasExtraProperties extensibleObject,
            List <ValidationResult> validationErrors,
            ValidationContext objectValidationContext,
            ObjectExtensionInfo objectExtensionInfo)
        {
            var properties = objectExtensionInfo.GetProperties();

            if (!properties.Any())
            {
                return;
            }

            foreach (var property in properties)
            {
                AddPropertyValidationErrors(
                    extensibleObject,
                    validationErrors,
                    objectValidationContext,
                    property,
                    extensibleObject.GetProperty(property.Name)
                    );
            }
        }
Ejemplo n.º 7
0
        private static bool CanMapProperty(
            [NotNull] string propertyName, [CanBeNull] ObjectExtensionInfo sourceObjectExtension, [CanBeNull] ObjectExtensionInfo destinationObjectExtension,
            MappingPropertyDefinitionChecks?definitionChecks = null,
            string[] ignoredProperties = null)
        {
            Check.NotNull(propertyName, nameof(propertyName));

            if (ignoredProperties != null &&
                ignoredProperties.Contains(propertyName))
            {
                return(false);
            }

            if (definitionChecks != null)
            {
                if (definitionChecks.Value.HasFlag(MappingPropertyDefinitionChecks.Source))
                {
                    if (sourceObjectExtension == null)
                    {
                        return(false);
                    }

                    if (!sourceObjectExtension.HasProperty(propertyName))
                    {
                        return(false);
                    }
                }

                if (definitionChecks.Value.HasFlag(MappingPropertyDefinitionChecks.Destination))
                {
                    if (destinationObjectExtension == null)
                    {
                        return(false);
                    }

                    if (!destinationObjectExtension.HasProperty(propertyName))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else
            {
                var sourcePropertyDefinition      = sourceObjectExtension?.GetPropertyOrNull(propertyName);
                var destinationPropertyDefinition = destinationObjectExtension?.GetPropertyOrNull(propertyName);

                if (sourcePropertyDefinition != null)
                {
                    if (destinationPropertyDefinition != null)
                    {
                        return(true);
                    }

                    if (sourcePropertyDefinition.CheckPairDefinitionOnMapping == false)
                    {
                        return(true);
                    }
                }
                else if (destinationPropertyDefinition != null)
                {
                    if (destinationPropertyDefinition.CheckPairDefinitionOnMapping == false)
                    {
                        return(true);
                    }
                }

                return(false);
            }
        }