BExIS.Xml.Helpers.Mapping.XmlSchemaManager.ConvertFacetToConstraint C# (CSharp) Метод

ConvertFacetToConstraint() приватный Метод

length, minLength,maxLength,pattern,enumeration,whiteSpace,maxInclusive,maxExclusive,minExclusive,minInclusive,totalDigits,fractionDigits
private ConvertFacetToConstraint ( XmlSchemaObject facet, MetadataAttribute attr, List constraints ) : Constraint
facet System.Xml.Schema.XmlSchemaObject
attr BExIS.Dlm.Entities.MetadataStructure.MetadataAttribute
constraints List
Результат Constraint
        private Constraint ConvertFacetToConstraint(XmlSchemaObject facet, MetadataAttribute attr, List<Constraint> constraints)
        {
            #region pattern constraints

                //if (facet is XmlSchemaWhiteSpaceFacet)
                //{
                //    XmlSchemaWhiteSpaceFacet defFacet = (XmlSchemaWhiteSpaceFacet)facet;

                //    return GetPatternConstraint(" ", GetDescription(defFacet.Annotation), true, attr);
                //}

                if (facet is XmlSchemaPatternFacet)
                {
                    XmlSchemaPatternFacet defFacet = (XmlSchemaPatternFacet)facet;
                    return GetPatternConstraint(defFacet.Value, GetDescription(defFacet.Annotation), false ,attr);
                }

            #endregion

            #region range constraints

                if (facet is XmlSchemaLengthFacet)
                {
                    XmlSchemaLengthFacet defFacet = (XmlSchemaLengthFacet)facet;

                    if (!IsRangeExist(constraints))
                    {

                        return GetRangeConstraint(Convert.ToDouble(defFacet.Value), Convert.ToDouble(defFacet.Value), GetDescription(defFacet.Annotation), false, true, true, attr);
                    }
                    else
                    {
                        double value = Convert.ToDouble(defFacet.Value);
                        RangeConstraint rc = GetRangeConstraint(constraints);
                        dataContainerManager.RemoveConstraint(rc);
                        // if value is bigger then Lowerbound us value
                        if (rc.Lowerbound < value) rc.Lowerbound = value;

                        // if value is smaller then Upperbound  us value
                        if (rc.Upperbound > value) rc.Upperbound = value;

                        rc.LowerboundIncluded = true;
                        rc.UpperboundIncluded = true;

                        constraints.Remove(rc);

                        return GetRangeConstraint(rc.Lowerbound, rc.Upperbound, GetDescription(defFacet.Annotation), false, rc.LowerboundIncluded, rc.UpperboundIncluded, attr);

                    }
                }

                if (facet is XmlSchemaMinLengthFacet)
                {
                    XmlSchemaMinLengthFacet defFacet = (XmlSchemaMinLengthFacet)facet;

                    if (!IsRangeExist(constraints))
                    {
                        return GetRangeConstraint(Convert.ToDouble(defFacet.Value), double.MaxValue, GetDescription(defFacet.Annotation), false, true, true, attr);
                    }
                    else
                    {
                        double value = Convert.ToDouble(defFacet.Value);
                        RangeConstraint rc = GetRangeConstraint(constraints);

                        dataContainerManager.RemoveConstraint(rc);

                        // if value is bigger then Lowerbound us value
                        if (rc.Lowerbound < value) rc.Lowerbound = value;

                        rc.LowerboundIncluded = true;

                        constraints.Remove(rc);

                        return GetRangeConstraint(rc.Lowerbound, rc.Upperbound, GetDescription(defFacet.Annotation), false, rc.LowerboundIncluded, rc.UpperboundIncluded, attr);
                    }

                }

                if (facet is XmlSchemaMaxLengthFacet)
                {
                    XmlSchemaMaxLengthFacet defFacet = (XmlSchemaMaxLengthFacet)facet;

                    if (!IsRangeExist(constraints))
                    {
                        return GetRangeConstraint(double.MinValue, Convert.ToDouble(defFacet.Value), GetDescription(defFacet.Annotation), false, true, true, attr);
                    }
                    else
                    {
                        double value = Convert.ToDouble(defFacet.Value);
                        RangeConstraint rc = GetRangeConstraint(constraints);
                        dataContainerManager.RemoveConstraint(rc);

                        // if value is smaller then Upperbound  us value
                        if (rc.Upperbound > value) rc.Upperbound = value;

                        rc.UpperboundIncluded = true;

                        constraints.Remove(rc);

                        return GetRangeConstraint(rc.Lowerbound, rc.Upperbound, GetDescription(defFacet.Annotation), false, rc.LowerboundIncluded, rc.UpperboundIncluded, attr);
                    }
                }

                if (facet is XmlSchemaMaxInclusiveFacet)
                {
                    XmlSchemaMaxInclusiveFacet defFacet = (XmlSchemaMaxInclusiveFacet)facet;

                    if (!IsRangeExist(constraints))
                    {
                        return GetRangeConstraint(0, Convert.ToDouble(defFacet.Value), GetDescription(defFacet.Annotation), false, true, true, attr);
                    }
                    else
                    {
                        double value = Convert.ToDouble(defFacet.Value);
                        RangeConstraint rc = GetRangeConstraint(constraints);
                        dataContainerManager.RemoveConstraint(rc);

                        // if value is smaller then Upperbound  us value
                        if (rc.Upperbound > value) rc.Upperbound = value;

                        rc.UpperboundIncluded = true;

                        constraints.Remove(rc);

                        return GetRangeConstraint(rc.Lowerbound, rc.Upperbound, GetDescription(defFacet.Annotation), false, rc.LowerboundIncluded, rc.UpperboundIncluded, attr);
                    }
                }

                if (facet is XmlSchemaMinInclusiveFacet)
                {
                    XmlSchemaMinInclusiveFacet defFacet = (XmlSchemaMinInclusiveFacet)facet;
                    if (!IsRangeExist(constraints))
                    {
                        return GetRangeConstraint(Convert.ToDouble(defFacet.Value), int.MaxValue, GetDescription(defFacet.Annotation), false, true, true, attr);
                    }
                    else
                    {
                        double value = Convert.ToDouble(defFacet.Value);
                        RangeConstraint rc = GetRangeConstraint(constraints);
                        dataContainerManager.RemoveConstraint(rc);

                        // if value is bigger then Lowerbound us value
                        if (rc.Lowerbound < value) rc.Lowerbound = value;

                        rc.LowerboundIncluded = true;

                        constraints.Remove(rc);

                        return GetRangeConstraint(rc.Lowerbound, rc.Upperbound, GetDescription(defFacet.Annotation), false, rc.LowerboundIncluded, rc.UpperboundIncluded, attr);
                    }
                }

                if (facet is XmlSchemaMaxExclusiveFacet)
                {
                    XmlSchemaMaxExclusiveFacet defFacet = (XmlSchemaMaxExclusiveFacet)facet;

                    if (!IsRangeExist(constraints))
                    {
                        return GetRangeConstraint(0, Convert.ToDouble(defFacet.Value), GetDescription(defFacet.Annotation), false, true, false, attr);
                    }
                    else
                    {
                        double value = Convert.ToDouble(defFacet.Value);
                        RangeConstraint rc = GetRangeConstraint(constraints);
                        dataContainerManager.RemoveConstraint(rc);

                        // if value is smaller then Upperbound  us value
                        if (rc.Upperbound > value) rc.Upperbound = value;

                        rc.UpperboundIncluded = false;

                        constraints.Remove(rc);

                        return GetRangeConstraint(rc.Lowerbound, rc.Upperbound, GetDescription(defFacet.Annotation), false, rc.LowerboundIncluded, rc.UpperboundIncluded, attr);
                    }
                }

                if (facet is XmlSchemaMinExclusiveFacet)
                {
                    XmlSchemaMinExclusiveFacet defFacet = (XmlSchemaMinExclusiveFacet)facet;
                    if (!IsRangeExist(constraints))
                    {
                        return GetRangeConstraint(Convert.ToDouble(defFacet.Value), int.MaxValue, GetDescription(defFacet.Annotation), false, false, true, attr);
                    }
                    else
                    {
                        double value = Convert.ToDouble(defFacet.Value);
                        RangeConstraint rc = GetRangeConstraint(constraints);
                        dataContainerManager.RemoveConstraint(rc);
                        // if value is bigger then Lowerbound us value
                        if (rc.Lowerbound < value) rc.Lowerbound = value;

                        rc.LowerboundIncluded = false;

                        constraints.Remove(rc);

                        return GetRangeConstraint(rc.Lowerbound, rc.Upperbound, GetDescription(defFacet.Annotation), false, rc.LowerboundIncluded, rc.UpperboundIncluded, attr);
                    }
                }

            #endregion

            if (facet is XmlSchemaTotalDigitsFacet)
            {

            }

            if (facet is XmlSchemaFractionDigitsFacet)
            {

            }

            /* special case
            if (facet is XmlSchemaEnumerationFacet)
            {
                return GetDomainConstraint((XmlSchemaEnumerationFacet)facet);
            }
             * */

            return null;
        }