Exemplo n.º 1
0
        protected override bool InternalEqualsTo(DefaultableMulti other)
        {
            PropertyConstraint otherContraint = (PropertyConstraint)other;

            return(this.Mode == otherContraint.Mode &&
                   Util.StringEqual(this.ErrorMessage, otherContraint.ErrorMessage, false));
        }
Exemplo n.º 2
0
        public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
        {
            PropertyConstraint email          = (PropertyConstraint)propertyValues["EmailConstraint"];
            PropertyConstraint future         = (PropertyConstraint)propertyValues["FutureConstraint"];
            PropertyConstraint length         = (PropertyConstraint)propertyValues["LengthConstraint"];
            PropertyConstraint notEmpty       = (PropertyConstraint)propertyValues["NotEmptyConstraint"];
            PropertyConstraint notNull        = (PropertyConstraint)propertyValues["NotNullConstraint"];
            PropertyConstraint notNullOrEmpty = (PropertyConstraint)propertyValues["NotNullOrEmptyConstraint"];
            PropertyConstraint past           = (PropertyConstraint)propertyValues["PastConstraint"];
            PropertyConstraint range          = (PropertyConstraint)propertyValues["RangeConstraint"];
            PropertyConstraint regex          = (PropertyConstraint)propertyValues["RegexConstraint"];
            //PropertyConstrainTypes constrainTypes = (PropertyConstrainTypes) propertyValues["ConstrainTypes"];

            OrmPropertyConstraints result = new OrmPropertyConstraints();

            result.UpdateConstraint(email);
            result.UpdateConstraint(future);
            result.UpdateConstraint(length);
            result.UpdateConstraint(notEmpty);
            result.UpdateConstraint(notNull);
            result.UpdateConstraint(notNullOrEmpty);
            result.UpdateConstraint(past);
            result.UpdateConstraint(range);
            result.UpdateConstraint(regex);
            //result.ConstrainTypes = constrainTypes;
            return(result);
        }
Exemplo n.º 3
0
        internal void UpdateConstraint(PropertyConstraint constraint)
        {
            switch (constraint.ConstrainType)
            {
            case PropertyConstrainType.Email:
            {
                this.EmailConstraint = (PropertyEmailConstraint)constraint;
                break;
            }

            case PropertyConstrainType.Future:
            {
                this.FutureConstraint = (PropertyFutureConstraint)constraint;
                break;
            }

            case PropertyConstrainType.Length:
            {
                this.LengthConstraint = (PropertyLengthConstraint)constraint;
                break;
            }

            case PropertyConstrainType.NotEmpty:
            {
                this.NotEmptyConstraint = (PropertyNotEmptyConstraint)constraint;
                break;
            }

            case PropertyConstrainType.NotNull:
            {
                this.NotNullConstraint = (PropertyNotNullConstraint)constraint;
                break;
            }

            case PropertyConstrainType.NotNullOrEmpty:
            {
                this.NotNullOrEmptyConstraint = (PropertyNotNullOrEmptyConstraint)constraint;
                break;
            }

            case PropertyConstrainType.Past:
            {
                this.PastConstraint = (PropertyPastConstraint)constraint;
                break;
            }

            case PropertyConstrainType.Range:
            {
                this.RangeConstraint = (PropertyRangeConstraint)constraint;
                break;
            }

            case PropertyConstrainType.Regex:
            {
                this.RegexConstraint = (PropertyRegexConstraint)constraint;
                break;
            }
            }
        }
Exemplo n.º 4
0
 protected override void InternalAssignFrom(DefaultableMulti other)
 {
     if (other is PropertyConstraint)
     {
         PropertyConstraint otherContraint = (PropertyConstraint)other;
         this.Used         = otherContraint.Used;
         this.Mode         = otherContraint.Mode;
         this.ErrorMessage = otherContraint.ErrorMessage;
     }
 }
Exemplo n.º 5
0
        public OrmPropertyConstraints Merge(OrmPropertyConstraints otherConstraints, MergeConflictAction mergeConflictAction)
        {
            OrmPropertyConstraints merged = new OrmPropertyConstraints();

            foreach (var constraint in this.AllConstraints)
            {
                PropertyConstrainType constrainType    = constraint.ConstrainType;
                PropertyConstraint    otherConstraint  = otherConstraints[constrainType];
                PropertyConstraint    mergedConstraint = (PropertyConstraint)constraint.MergeChanges(otherConstraint, mergeConflictAction);
                merged.UpdateConstraint(mergedConstraint);
            }
            return(merged);
        }
Exemplo n.º 6
0
        public IOrmAttribute MergeChanges(IOrmAttribute otherAttribute, MergeConflictAction mergeConflictAction)
        {
            PropertyConstraint mergedConstraint = CreateInstance(this.ConstrainType);
            PropertyConstraint other            = (PropertyConstraint)otherAttribute;

            string mergedValueType;
            PropertyConstrainMode mergedMode;
            string mergedErrorMessage;

            if ((this.Used && other.Used) || (!this.Used && !other.Used))
            {
                if (mergeConflictAction == MergeConflictAction.TakeOther)
                {
                    mergedValueType    = other.ValueType;
                    mergedMode         = other.Mode;
                    mergedErrorMessage = other.ErrorMessage;
                }
                else
                {
                    mergedValueType    = this.ValueType;
                    mergedMode         = this.Mode;
                    mergedErrorMessage = this.ErrorMessage;
                }
            }
            else
            {
                if (this.Used)
                {
                    mergedValueType    = this.ValueType;
                    mergedMode         = this.Mode;
                    mergedErrorMessage = this.ErrorMessage;
                }
                else // other.IsCustom()
                {
                    mergedValueType    = other.ValueType;
                    mergedMode         = other.Mode;
                    mergedErrorMessage = other.ErrorMessage;
                }
            }

            mergedConstraint.Mode         = mergedMode;
            mergedConstraint.ErrorMessage = mergedErrorMessage;
            mergedConstraint.ValueType    = mergedValueType;
            if (mergedConstraint.Used)
            {
                InternalMergeChanges(ref mergedConstraint, other, mergeConflictAction);
            }

            return(mergedConstraint);
        }
Exemplo n.º 7
0
        public void DeserializeFromXml(XmlProxy xmlRoot)
        {
            List <PropertyConstraint> list = new List <PropertyConstraint>();

            foreach (XmlProxy xmlChild in xmlRoot.Childs)
            {
                PropertyConstrainType propertyConstrainType = PropertyConstraint.DeserializeType(xmlChild);
                PropertyConstraint    propertyConstraint    = PropertyConstraint.CreateInstance(propertyConstrainType);
                propertyConstraint.DeserializeFromXml(xmlChild);
                list.Add(propertyConstraint);
            }
            foreach (PropertyConstraint constraint in list)
            {
                UpdateConstraint(constraint);
            }
        }
Exemplo n.º 8
0
        protected override void InternalMergeChanges(ref PropertyConstraint mergedConstraint, PropertyConstraint otherConstraint,
                                                     MergeConflictAction mergeConflictAction)
        {
            PropertyRegexConstraint other  = (PropertyRegexConstraint)otherConstraint;
            PropertyRegexConstraint merged = (PropertyRegexConstraint)mergedConstraint;

            Defaultable <string> mergedPattern = this.GetPatternAsDefaultable().Merge(other.GetPatternAsDefaultable(),
                                                                                      mergeConflictAction);

            merged.Pattern = mergedPattern.IsCustom() ? mergedPattern.Value : string.Empty;

            Defaultable <RegexOptions> mergedOptions =
                this.GetOptionsAsDefaultable().Merge(other.GetOptionsAsDefaultable(), mergeConflictAction);

            merged.Options = mergedOptions.IsCustom() ? mergedOptions.Value : RegexOptions.Compiled;
        }
Exemplo n.º 9
0
        protected override void InternalMergeChanges(ref PropertyConstraint mergedConstraint, PropertyConstraint otherConstraint,
                                                     MergeConflictAction mergeConflictAction)
        {
            PropertyRangeConstraint other  = (PropertyRangeConstraint)otherConstraint;
            PropertyRangeConstraint merged = (PropertyRangeConstraint)mergedConstraint;

            Defaultable <ObjectValue> mergedMin = GetMinAsDefaultable().Merge(other.GetMinAsDefaultable(),
                                                                              mergeConflictAction);

            merged.Min         = new ObjectValueInfo();
            merged.Min.Enabled = mergedMin.IsCustom();
            merged.Min.Value   = mergedMin.Value;

            Defaultable <ObjectValue> mergedMax = GetMaxAsDefaultable().Merge(other.GetMaxAsDefaultable(),
                                                                              mergeConflictAction);

            merged.Max         = new ObjectValueInfo();
            merged.Max.Enabled = mergedMax.IsCustom();
            merged.Max.Value   = mergedMax.Value;
        }
Exemplo n.º 10
0
 protected virtual void InternalMergeChanges(ref PropertyConstraint mergedConstraint, PropertyConstraint otherConstraint,
                                             MergeConflictAction mergeConflictAction)
 {
 }