Example #1
0
//        public IOrmAttribute CreateOrmAttribute()
//        {
//            return InternalCreateOrmAttribute();
//        }
//
        //protected internal abstract PropertyConstraintOrmAttribute InternalCreateOrmAttribute();


        internal static PropertyConstraint CreateInstance(PropertyConstrainType constrainType)
        {
            switch (constrainType)
            {
            case PropertyConstrainType.Email:
                return(new PropertyEmailConstraint());

            case PropertyConstrainType.Future:
                return(new PropertyFutureConstraint());

            case PropertyConstrainType.Length:
                return(new PropertyLengthConstraint());

            case PropertyConstrainType.NotEmpty:
                return(new PropertyNotEmptyConstraint());

            case PropertyConstrainType.NotNull:
                return(new PropertyNotNullConstraint());

            case PropertyConstrainType.NotNullOrEmpty:
                return(new PropertyNotNullOrEmptyConstraint());

            case PropertyConstrainType.Past:
                return(new PropertyPastConstraint());

            case PropertyConstrainType.Range:
                return(new PropertyRangeConstraint());

            case PropertyConstrainType.Regex:
                return(new PropertyRegexConstraint());

            default:
                throw new ApplicationException("unknown constrainType");
            }
        }
Example #2
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);
        }
Example #3
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);
            }
        }
Example #4
0
 public PropertyConstraint this[PropertyConstrainType constrainType]
 {
     get { return(this.AllConstraints.Single(constraint => constraint.ConstrainType == constrainType)); }
 }
Example #5
0
        internal static PropertyConstrainType DeserializeType(XmlProxy xml)
        {
            PropertyConstrainType type = (PropertyConstrainType)xml.GetAttr("type", (int)PropertyConstrainType.NotNull);

            return(type);
        }