Пример #1
0
        internal override Exception CheckValueFacets(XmlQualifiedName value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction = datatype.Restriction;
            RestrictionFlags  flags       = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);

            if (flags != 0)
            {
                int length = value.ToString().Length;
                if (((flags & RestrictionFlags.Length) != 0) && (restriction.Length != length))
                {
                    return(new XmlSchemaException("Sch_LengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.MinLength) != 0) && (length < restriction.MinLength))
                {
                    return(new XmlSchemaException("Sch_MinLengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.MaxLength) != 0) && (restriction.MaxLength < length))
                {
                    return(new XmlSchemaException("Sch_MaxLengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration))
                {
                    return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
                }
            }
            return(null);
        }
Пример #2
0
        internal void CheckFacets(CompiledFacets genFacets)
        {
            if (genFacets != null)
            {
                RestrictionFlags flags = genFacets.Flags;

                if ((flags & RestrictionFlags.Length) != 0)
                {
                    _length = genFacets.Length;
                }

                if ((flags & RestrictionFlags.MinLength) != 0)
                {
                    _minLength = genFacets.MinLength;
                }

                if ((flags & RestrictionFlags.MaxLength) != 0)
                {
                    _maxLength = genFacets.MaxLength;
                }

                if ((flags & RestrictionFlags.Enumeration) != 0)
                {
                    _allowedValues = genFacets.Enumeration;
                }
            }
        }
Пример #3
0
        internal void CheckFacets(CompiledFacets genFacets)
        {
            if (genFacets != null)
            {
                RestrictionFlags flags = genFacets.Flags;

                if ((flags & RestrictionFlags.MaxInclusive) != 0)
                {
                    this.MaxBound = (DateTime)genFacets.MaxInclusive;
                }

                if ((flags & RestrictionFlags.MaxExclusive) != 0)
                {
                    this.MaxBound = ((DateTime)genFacets.MaxExclusive).Subtract(_step);
                }

                if ((flags & RestrictionFlags.MinInclusive) != 0)
                {
                    this.MinBound = (DateTime)genFacets.MinInclusive;
                }

                if ((flags & RestrictionFlags.MinExclusive) != 0)
                {
                    this.MinBound = ((DateTime)genFacets.MinExclusive).Add(_step);
                }

                if ((flags & RestrictionFlags.Enumeration) != 0)
                {
                    _allowedValues = genFacets.Enumeration;
                }
            }
        }
        internal override Exception CheckValueFacets(TimeSpan value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction = datatype.Restriction;
            RestrictionFlags  flags       = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);

            if (((flags & RestrictionFlags.MaxInclusive) != 0) && (TimeSpan.Compare(value, (TimeSpan)restriction.MaxInclusive) > 0))
            {
                return(new XmlSchemaException("Sch_MaxInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MaxExclusive) != 0) && (TimeSpan.Compare(value, (TimeSpan)restriction.MaxExclusive) >= 0))
            {
                return(new XmlSchemaException("Sch_MaxExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinInclusive) != 0) && (TimeSpan.Compare(value, (TimeSpan)restriction.MinInclusive) < 0))
            {
                return(new XmlSchemaException("Sch_MinInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinExclusive) != 0) && (TimeSpan.Compare(value, (TimeSpan)restriction.MinExclusive) <= 0))
            {
                return(new XmlSchemaException("Sch_MinExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(null);
        }
        internal virtual Exception CheckLexicalFacets(ref string parsedString, object value, NameTable nameTable, XNamespaceResolver resolver, SimpleTypeValidator type)
        {
            RestrictionFacets facets = type.RestrictionFacets;

            if (facets == null || !facets.HasLexicalFacets)
            {
                return(null);
            }

            RestrictionFlags    flags     = facets.Flags;
            XmlSchemaWhiteSpace wsPattern = XmlSchemaWhiteSpace.Collapse;


            if ((flags & RestrictionFlags.WhiteSpace) != 0)
            {
                if (facets.WhiteSpace == XmlSchemaWhiteSpace.Collapse)
                {
                    wsPattern = XmlSchemaWhiteSpace.Collapse;
                }
                else if (facets.WhiteSpace == XmlSchemaWhiteSpace.Preserve)
                {
                    wsPattern = XmlSchemaWhiteSpace.Preserve;
                }
            }


            return(CheckLexicalFacets(ref parsedString, type, facets.Patterns, wsPattern));
        }
        internal override Exception CheckValueFacets(object value, SimpleTypeValidator type)
        {
            RestrictionFacets facets = type.RestrictionFacets;

            if (facets == null || !facets.HasValueFacets)
            {
                return(null);
            }
            RestrictionFlags  flags    = facets.Flags;
            XmlSchemaDatatype datatype = type.DataType;

            if ((flags & RestrictionFlags.Enumeration) != 0)
            {
                ArrayList enums = facets.Enumeration;

                if (!MatchEnumeration(value, enums, datatype))
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.Enumeration,
                                                       facets.Enumeration,
                                                       value));
                }
            }

            return(null);
        }
Пример #7
0
        internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype)
        {
            Array             array       = value as Array;
            RestrictionFacets restriction = datatype.Restriction;
            RestrictionFlags  flags       = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);

            if ((flags & (RestrictionFlags.MaxLength | RestrictionFlags.MinLength | RestrictionFlags.Length)) != 0)
            {
                int length = array.Length;
                if (((flags & RestrictionFlags.Length) != 0) && (restriction.Length != length))
                {
                    return(new XmlSchemaException("Sch_LengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.MinLength) != 0) && (length < restriction.MinLength))
                {
                    return(new XmlSchemaException("Sch_MinLengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.MaxLength) != 0) && (restriction.MaxLength < length))
                {
                    return(new XmlSchemaException("Sch_MaxLengthConstraintFailed", string.Empty));
                }
            }
            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, datatype))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(null);
        }
        internal override Exception CheckValueFacets(DateTime value, SimpleTypeValidator type)
        {
            RestrictionFacets facets = type.RestrictionFacets;

            if (facets == null || !facets.HasValueFacets)
            {
                return(null);
            }

            RestrictionFlags  flags    = facets.Flags;
            XmlSchemaDatatype datatype = type.DataType;

            if ((flags & RestrictionFlags.Enumeration) != 0)
            {
                ArrayList enums = facets.Enumeration;

                if (!MatchEnumeration(value, enums, datatype))
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.Enumeration,
                                                       facets.Enumeration,
                                                       value));
                }
            }


            if ((flags & RestrictionFlags.MinInclusive) != 0)
            {
                if (DateTime.Compare(value, (DateTime)datatype.ChangeType(facets.MinInclusive, typeof(DateTime))) < 0)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MinInclusive, facets.MinInclusive, value));
                }
            }

            if ((flags & RestrictionFlags.MinExclusive) != 0)
            {
                if (DateTime.Compare(value, (DateTime)datatype.ChangeType(facets.MinExclusive, typeof(DateTime))) <= 0)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MinExclusive, facets.MinInclusive, value));
                }
            }

            if ((flags & RestrictionFlags.MaxExclusive) != 0)
            {
                if (DateTime.Compare(value, (DateTime)datatype.ChangeType(facets.MaxExclusive, typeof(DateTime))) >= 0)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MaxExclusive, facets.MaxExclusive, value));
                }
            }

            if ((flags & RestrictionFlags.MaxInclusive) != 0)
            {
                if (DateTime.Compare(value, (DateTime)datatype.ChangeType(facets.MaxInclusive, typeof(DateTime))) > 0)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MaxInclusive, facets.MaxInclusive, value));
                }
            }


            return(null);
        }
        internal override Exception CheckValueFacets(XmlQualifiedName value, SimpleTypeValidator type)
        {
            RestrictionFacets facets = type.RestrictionFacets;

            if (facets == null || !facets.HasValueFacets)
            {
                return(null);
            }


            if (facets == null)
            {
                return(null);
            }
            RestrictionFlags  flags    = facets.Flags;
            XmlSchemaDatatype datatype = type.DataType;


            if ((flags & RestrictionFlags.Enumeration) != 0)
            {
                ArrayList enums = facets.Enumeration;


                if (!MatchEnumeration(value, enums, datatype))
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.Enumeration,
                                                       facets.Enumeration,
                                                       value));
                }
            }

            string strValue = value.ToString();
            int    length   = strValue.Length;

            if ((flags & RestrictionFlags.Length) != 0)
            {
                if (length != facets.Length)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.Length, facets.Length, value));
                }
            }

            if ((flags & RestrictionFlags.MaxLength) != 0)
            {
                if (length > facets.MaxLength)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MaxLength, facets.MaxLength, value));
                }
            }

            if ((flags & RestrictionFlags.MinLength) != 0)
            {
                if (length < facets.MinLength)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MinLength, facets.MinLength, value));
                }
            }

            return(null);
        }
        internal Exception CheckValueFacets(string value, XmlSchemaDatatype datatype, bool verifyUri)
        {
            int length = value.Length;
            RestrictionFacets restriction = datatype.Restriction;
            RestrictionFlags  flags       = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);
            Exception         exception   = this.CheckBuiltInFacets(value, datatype.TypeCode, verifyUri);

            if (exception != null)
            {
                return(exception);
            }
            if (flags != 0)
            {
                if (((flags & RestrictionFlags.Length) != 0) && (restriction.Length != length))
                {
                    return(new XmlSchemaException("Sch_LengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.MinLength) != 0) && (length < restriction.MinLength))
                {
                    return(new XmlSchemaException("Sch_MinLengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.MaxLength) != 0) && (restriction.MaxLength < length))
                {
                    return(new XmlSchemaException("Sch_MaxLengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, datatype))
                {
                    return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
                }
            }
            return(null);
        }
Пример #11
0
 private void CheckDupFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode)
 {
     if ((this.derivedRestriction.Flags & flag) != 0)
     {
         throw new XmlSchemaException(errorCode, facet);
     }
 }
Пример #12
0
        internal override Exception CheckValueFacets(double value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction    = datatype.Restriction;
            RestrictionFlags  flags          = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);
            XmlValueConverter valueConverter = datatype.ValueConverter;

            if (((flags & RestrictionFlags.MaxInclusive) != 0) && (value > valueConverter.ToDouble(restriction.MaxInclusive)))
            {
                return(new XmlSchemaException("Sch_MaxInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MaxExclusive) != 0) && (value >= valueConverter.ToDouble(restriction.MaxExclusive)))
            {
                return(new XmlSchemaException("Sch_MaxExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinInclusive) != 0) && (value < valueConverter.ToDouble(restriction.MinInclusive)))
            {
                return(new XmlSchemaException("Sch_MinInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinExclusive) != 0) && (value <= valueConverter.ToDouble(restriction.MinExclusive)))
            {
                return(new XmlSchemaException("Sch_MinExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, valueConverter))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(null);
        }
Пример #13
0
 private void CheckProhibitedFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode)
 {
     if ((this.validRestrictionFlags & flag) == 0)
     {
         throw new XmlSchemaException(errorCode, this.datatype.TypeCodeString, facet);
     }
 }
Пример #14
0
        internal void CheckFacets(CompiledFacets genFacets)
        {
            if (genFacets != null)
            {
                RestrictionFlags flags = genFacets.Flags;

                if ((flags & RestrictionFlags.MaxInclusive) != 0)
                {
                    this.MaxBound = (float)genFacets.MaxInclusive;
                }

                if ((flags & RestrictionFlags.MaxExclusive) != 0)
                {
                    this.MaxBound = (float)genFacets.MaxExclusive - 1;
                }

                if ((flags & RestrictionFlags.MinInclusive) != 0)
                {
                    this.MinBound = (float)genFacets.MinInclusive;
                }

                if ((flags & RestrictionFlags.MinExclusive) != 0)
                {
                    this.MinBound = (float)genFacets.MinExclusive + 1;
                }

                if ((flags & RestrictionFlags.Enumeration) != 0)
                {
                    _allowedValues = genFacets.Enumeration;
                }
            }
        }
        internal Exception CheckValueFacets(string value, SimpleTypeValidator type, bool verifyUri)
        {
            //Length, MinLength, MaxLength
            int length = value.Length;
            RestrictionFacets facets = type.RestrictionFacets;

            if (facets == null)
            {
                return(null);
            }
            RestrictionFlags  flags    = facets.Flags;
            XmlSchemaDatatype datatype = type.DataType;

            Exception exception;

            exception = CheckBuiltInFacets(value, datatype.TypeCode, verifyUri);
            if (exception != null)
            {
                return(exception);
            }

            if ((flags & RestrictionFlags.Enumeration) != 0)
            {
                ArrayList enums = facets.Enumeration;


                if (!MatchEnumeration(value, enums, datatype))
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.Enumeration,
                                                       facets.Enumeration,
                                                       value));
                }
            }

            if ((flags & RestrictionFlags.Length) != 0)
            {
                if (length != facets.Length)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.Length, facets.Length, value));
                }
            }

            if ((flags & RestrictionFlags.MaxLength) != 0)
            {
                if (length > facets.MaxLength)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MaxLength, facets.MaxLength, value));
                }
            }

            if ((flags & RestrictionFlags.MinLength) != 0)
            {
                if (length < facets.MinLength)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MinLength, facets.MinLength, value));
                }
            }

            return(null);
        }
Пример #16
0
 private void SetFlag(RestrictionFlags flag)
 {
     this.derivedRestriction.Flags |= flag;
     if ((this.baseFixedFlags & flag) != 0)
     {
         this.derivedRestriction.FixedFlags |= flag;
     }
 }
Пример #17
0
 private void SetFlag(XmlSchemaFacet facet, RestrictionFlags flag)
 {
     this.derivedRestriction.Flags |= flag;
     if (facet.IsFixed)
     {
         this.derivedRestriction.FixedFlags |= flag;
     }
 }
Пример #18
0
        public LinqToXsdFacetException(RestrictionFlags flags,
                                  object facetValue,
                                  object value)
        : base(CreateMessage(flags.ToString(), facetValue, value)){

            
            
        }
Пример #19
0
        internal void CheckFacets(CompiledFacets genFacets)
        {
            if (genFacets != null)
            {
                RestrictionFlags flags = genFacets.Flags;

                if ((flags & RestrictionFlags.MaxInclusive) != 0)
                {
                    this.MaxBound = (decimal)Convert.ChangeType(genFacets.MaxInclusive, typeof(decimal));
                }

                if ((flags & RestrictionFlags.MaxExclusive) != 0)
                {
                    this.MaxBound = (decimal)Convert.ChangeType(genFacets.MaxExclusive, typeof(decimal)) - 1;
                }

                if ((flags & RestrictionFlags.MinInclusive) != 0)
                {
                    this.MinBound = (decimal)Convert.ChangeType(genFacets.MinInclusive, typeof(decimal));
                }

                if ((flags & RestrictionFlags.MinExclusive) != 0)
                {
                    this.MinBound = (decimal)Convert.ChangeType(genFacets.MinExclusive, typeof(decimal)) + 1;
                }

                if ((flags & RestrictionFlags.Enumeration) != 0)
                {
                    _allowedValues = genFacets.Enumeration;
                }

                if ((flags & RestrictionFlags.TotalDigits) != 0)
                {
                    decimal totalDigitsValue = (decimal)Math.Pow(10, genFacets.TotalDigits) - 1;

                    if (totalDigitsValue <= this.MaxBound)
                    {                     //Use the lower of totalDigits value and maxInc/maxEx
                        this.MaxBound = totalDigitsValue;
                        this.MinBound = 0 - this.MaxBound;
                    }
                }

                if ((flags & RestrictionFlags.FractionDigits) != 0 && genFacets.FractionDigits > 0)
                {
                    if ((flags & RestrictionFlags.TotalDigits) != 0)
                    {
                        //if (T,F) is (6,3) the max value is not 999.999 but 99999.9d but we are going with the smaller range on the integral part to generate more varied fractional part.
                        int    range        = genFacets.TotalDigits - genFacets.FractionDigits;
                        double integralPart = Math.Pow(10, range) - 1;
                        double fractionPart = integralPart / Math.Pow(10, range);
                        this.MaxBound = (decimal)(integralPart + fractionPart);
                        this.MinBound = 0 - this.MaxBound;
                    }
                }
            }
        }
        internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction = datatype.Restriction;
            RestrictionFlags  flags       = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);

            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, datatype))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(null);
        }
Пример #21
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction) {
     firstPattern = true;
     regStr = null;
     pattern_facet = null;
     datatype = baseDatatype;
     derivedRestriction = restriction;
     baseFlags = datatype.Restriction != null ? datatype.Restriction.Flags : 0;
     baseFixedFlags = datatype.Restriction != null ? datatype.Restriction.FixedFlags : 0;
     validRestrictionFlags = datatype.ValidRestrictionFlags;
     nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     builtInEnum = !(datatype is Datatype_union || datatype is Datatype_List) ? datatype.TypeCode : 0;
     builtInType = (int)builtInEnum > 0 ? DatatypeImplementation.GetSimpleTypeFromTypeCode(builtInEnum).Datatype : datatype;
 }
Пример #22
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction)
 {
     this.firstPattern          = true;
     this.regStr                = null;
     this.pattern_facet         = null;
     this.datatype              = baseDatatype;
     this.derivedRestriction    = restriction;
     this.baseFlags             = (this.datatype.Restriction != null) ? this.datatype.Restriction.Flags : ((RestrictionFlags)0);
     this.baseFixedFlags        = (this.datatype.Restriction != null) ? this.datatype.Restriction.FixedFlags : ((RestrictionFlags)0);
     this.validRestrictionFlags = this.datatype.ValidRestrictionFlags;
     this.nonNegativeInt        = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     this.builtInEnum           = (!(this.datatype is Datatype_union) && !(this.datatype is Datatype_List)) ? this.datatype.TypeCode : XmlTypeCode.None;
     this.builtInType           = (this.builtInEnum > XmlTypeCode.None) ? DatatypeImplementation.GetSimpleTypeFromTypeCode(this.builtInEnum).Datatype : this.datatype;
 }
Пример #23
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction)
 {
     _firstPattern = true;
     _regStr = null;
     _pattern_facet = null;
     _datatype = baseDatatype;
     _derivedRestriction = restriction;
     _baseFlags = _datatype.Restriction != null ? _datatype.Restriction.Flags : 0;
     _baseFixedFlags = _datatype.Restriction != null ? _datatype.Restriction.FixedFlags : 0;
     _validRestrictionFlags = _datatype.ValidRestrictionFlags;
     _nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     _builtInEnum = !(_datatype is Datatype_union || _datatype is Datatype_List) ? _datatype.TypeCode : 0;
     _builtInType = (int)_builtInEnum > 0 ? DatatypeImplementation.GetSimpleTypeFromTypeCode(_builtInEnum).Datatype : _datatype;
 }
        internal override Exception CheckValueFacets(decimal value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction    = datatype.Restriction;
            RestrictionFlags  flags          = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);
            XmlValueConverter valueConverter = datatype.ValueConverter;

            if ((value > this.maxValue) || (value < this.minValue))
            {
                return(new OverflowException(Res.GetString("XmlConvert_Overflow", new object[] { value.ToString(CultureInfo.InvariantCulture), datatype.TypeCodeString })));
            }
            if (flags == 0)
            {
                return(null);
            }
            if (((flags & RestrictionFlags.MaxInclusive) != 0) && (value > valueConverter.ToDecimal(restriction.MaxInclusive)))
            {
                return(new XmlSchemaException("Sch_MaxInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MaxExclusive) != 0) && (value >= valueConverter.ToDecimal(restriction.MaxExclusive)))
            {
                return(new XmlSchemaException("Sch_MaxExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinInclusive) != 0) && (value < valueConverter.ToDecimal(restriction.MinInclusive)))
            {
                return(new XmlSchemaException("Sch_MinInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinExclusive) != 0) && (value <= valueConverter.ToDecimal(restriction.MinExclusive)))
            {
                return(new XmlSchemaException("Sch_MinExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, valueConverter))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(this.CheckTotalAndFractionDigits(value, restriction.TotalDigits, restriction.FractionDigits, (flags & RestrictionFlags.TotalDigits) != 0, (flags & RestrictionFlags.FractionDigits) != 0));
        }
Пример #25
0
        public static CodeExpression CreateFacets(ClrSimpleTypeInfo type)
        {
            CompiledFacets facets = type.RestrictionFacets;

            CodeObjectCreateExpression createFacets = new CodeObjectCreateExpression();

            createFacets.CreateType = new CodeTypeReference(Constants.RestrictionFacets);

            RestrictionFlags flags = facets.Flags;

            if (flags == 0)
            {
                return(new CodePrimitiveExpression(null));
            }
            else
            {
                CodeCastExpression cast = new CodeCastExpression(new CodeTypeReference(Constants.RestrictionFlags),
                                                                 new CodePrimitiveExpression(
                                                                     System.Convert.ToInt32(flags, CultureInfo.InvariantCulture.NumberFormat)));
                createFacets.Parameters.Add(cast);
            }


            if ((flags & RestrictionFlags.Enumeration) != 0)
            {
                CodeArrayCreateExpression enums = new CodeArrayCreateExpression();
                enums.CreateType = new CodeTypeReference("System.Object");

                foreach (object o in facets.Enumeration)
                {
                    GetCreateValueExpression(o, type, enums.Initializers);
                }

                createFacets.Parameters.Add(enums);
            }
            else
            {
                createFacets.Parameters.Add(new CodePrimitiveExpression(null));
            }

            int fractionDigits = default(int);

            if ((flags & RestrictionFlags.FractionDigits) != 0)
            {
                fractionDigits = facets.FractionDigits;
            }

            createFacets.Parameters.Add(new CodePrimitiveExpression(fractionDigits));

            int length = default(int);

            if ((flags & RestrictionFlags.Length) != 0)
            {
                length = facets.Length;
            }

            createFacets.Parameters.Add(new CodePrimitiveExpression(length));

            object maxExclusive = default(object);

            if ((flags & RestrictionFlags.MaxExclusive) != 0)
            {
                maxExclusive = facets.MaxExclusive;
            }

            GetCreateValueExpression(maxExclusive, type, createFacets.Parameters);


            object maxInclusive = default(object);

            if ((flags & RestrictionFlags.MaxInclusive) != 0)
            {
                maxInclusive = facets.MaxInclusive;
            }

            GetCreateValueExpression(maxInclusive, type, createFacets.Parameters);


            int maxLength = default(int);

            if ((flags & RestrictionFlags.MaxLength) != 0)
            {
                maxLength = facets.MaxLength;
            }

            createFacets.Parameters.Add(new CodePrimitiveExpression(maxLength));

            object minExclusive = default(object);

            if ((flags & RestrictionFlags.MinExclusive) != 0)
            {
                minExclusive = facets.MinExclusive;
            }

            GetCreateValueExpression(minExclusive, type, createFacets.Parameters);


            object minInclusive = default(object);

            if ((flags & RestrictionFlags.MinInclusive) != 0)
            {
                minInclusive = facets.MinInclusive;
            }

            GetCreateValueExpression(minInclusive, type, createFacets.Parameters);


            int minLength = default(int);

            if ((flags & RestrictionFlags.MinLength) != 0)
            {
                minLength = facets.MinLength;
            }

            createFacets.Parameters.Add(new CodePrimitiveExpression(minLength));

            if ((flags & RestrictionFlags.Pattern) != 0)
            {
                CodeArrayCreateExpression patternStrs = new CodeArrayCreateExpression();
                patternStrs.CreateType = new CodeTypeReference(XTypedServices.typeOfString);

                foreach (object o in facets.Patterns)
                {
                    string str = o.ToString();
                    patternStrs.Initializers.Add(new CodePrimitiveExpression(str));
                }

                createFacets.Parameters.Add(patternStrs);
            }
            else
            {
                createFacets.Parameters.Add(new CodePrimitiveExpression(null));
            }

            int totalDigits = default(int);

            if ((flags & RestrictionFlags.TotalDigits) != 0)
            {
                totalDigits = facets.TotalDigits;
            }

            createFacets.Parameters.Add(new CodePrimitiveExpression(totalDigits));

            XmlSchemaWhiteSpace ws = facets.WhiteSpace;

            createFacets.Parameters.Add(
                CodeDomHelper.CreateFieldReference(Constants.XmlSchemaWhiteSpace, ws.ToString()));


            return(createFacets);
        }
Пример #26
0
        public void compileFacets(XmlSchemaSimpleType simpleType)
        {
            XmlSchemaSimpleType type           = simpleType;
            XmlSchemaSimpleType enumSimpleType = null; //simpletype that has most restricted enums.

            flags = 0;
            while (type != null &&
                   !String.Equals(type.QualifiedName.Namespace, Constants.XSD, StringComparison.Ordinal))
            {
                XmlSchemaSimpleTypeRestriction simpleTypeRestriction = type.Content as XmlSchemaSimpleTypeRestriction;
                if (simpleTypeRestriction != null)
                {
                    foreach (XmlSchemaFacet facet in simpleTypeRestriction.Facets)
                    {
                        if (facet is XmlSchemaMinLengthFacet)
                        {
                            if ((flags & RestrictionFlags.MinLength) == 0)
                            {
                                minLength = XmlConvert.ToInt32(facet.Value);
                                flags    |= RestrictionFlags.MinLength;
                            }
                        }
                        else if (facet is XmlSchemaMaxLengthFacet)
                        {
                            if ((flags & RestrictionFlags.MaxLength) == 0)
                            {
                                maxLength = XmlConvert.ToInt32(facet.Value);
                                flags    |= RestrictionFlags.MaxLength;
                            }
                        }
                        else if (facet is XmlSchemaLengthFacet)
                        {
                            if ((flags & RestrictionFlags.Length) == 0)
                            {
                                length = XmlConvert.ToInt32(facet.Value);
                                flags |= RestrictionFlags.Length;
                            }
                        }
                        else if (facet is XmlSchemaEnumerationFacet)
                        {
                            if (enumSimpleType == null)
                            {
                                enumerations   = new ArrayList();
                                flags         |= RestrictionFlags.Enumeration;
                                enumSimpleType = type;
                            }
                            else if (enumSimpleType != type)
                            {
                                continue;
                            }

                            enumerations.Add(type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null));
                        }
                        else if (facet is XmlSchemaPatternFacet)
                        {
                            if (patterns == null)
                            {
                                patterns = new ArrayList();
                                flags   |= RestrictionFlags.Pattern;
                            }

                            patterns.Add(facet.Value);
                        }
                        else if (facet is XmlSchemaMaxInclusiveFacet)
                        {
                            if ((flags & RestrictionFlags.MaxInclusive) == 0)
                            {
                                maxInclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null);
                                flags       |= RestrictionFlags.MaxInclusive;
                            }
                        }
                        else if (facet is XmlSchemaMaxExclusiveFacet)
                        {
                            if ((flags & RestrictionFlags.MaxExclusive) == 0)
                            {
                                maxExclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null);
                                flags       |= RestrictionFlags.MaxExclusive;
                            }
                        }
                        else if (facet is XmlSchemaMinExclusiveFacet)
                        {
                            if ((flags & RestrictionFlags.MinExclusive) == 0)
                            {
                                minExclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null);
                                flags       |= RestrictionFlags.MinExclusive;
                            }
                        }
                        else if (facet is XmlSchemaMinInclusiveFacet)
                        {
                            if ((flags & RestrictionFlags.MinInclusive) == 0)
                            {
                                minInclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null);
                                flags       |= RestrictionFlags.MinInclusive;
                            }
                        }
                        else if (facet is XmlSchemaFractionDigitsFacet)
                        {
                            if ((flags & RestrictionFlags.FractionDigits) == 0)
                            {
                                fractionDigits = XmlConvert.ToInt32(facet.Value);
                                flags         |= RestrictionFlags.FractionDigits;
                            }
                        }
                        else if (facet is XmlSchemaTotalDigitsFacet)
                        {
                            if ((flags & RestrictionFlags.TotalDigits) == 0)
                            {
                                totalDigits = XmlConvert.ToInt32(facet.Value);
                                flags      |= RestrictionFlags.TotalDigits;
                            }
                        }
                        else if (facet is XmlSchemaWhiteSpaceFacet)
                        {
                            if ((flags & RestrictionFlags.WhiteSpace) == 0)
                            {
                                if (facet.Value == "preserve")
                                {
                                    whiteSpace = XmlSchemaWhiteSpace.Preserve;
                                }
                                else if (facet.Value == "replace")
                                {
                                    whiteSpace = XmlSchemaWhiteSpace.Replace;
                                }
                                else if (facet.Value == "collapse")
                                {
                                    whiteSpace = XmlSchemaWhiteSpace.Collapse;
                                }

                                flags |= RestrictionFlags.WhiteSpace;
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                }

                type = type.BaseXmlSchemaType as XmlSchemaSimpleType;
            }
        }
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction)
 {
     this.firstPattern = true;
     this.regStr = null;
     this.pattern_facet = null;
     this.datatype = baseDatatype;
     this.derivedRestriction = restriction;
     this.baseFlags = (this.datatype.Restriction != null) ? this.datatype.Restriction.Flags : ((RestrictionFlags) 0);
     this.baseFixedFlags = (this.datatype.Restriction != null) ? this.datatype.Restriction.FixedFlags : ((RestrictionFlags) 0);
     this.validRestrictionFlags = this.datatype.ValidRestrictionFlags;
     this.nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     this.builtInEnum = (!(this.datatype is Datatype_union) && !(this.datatype is Datatype_List)) ? this.datatype.TypeCode : XmlTypeCode.None;
     this.builtInType = (this.builtInEnum > XmlTypeCode.None) ? DatatypeImplementation.GetSimpleTypeFromTypeCode(this.builtInEnum).Datatype : this.datatype;
 }
Пример #28
0
        public RestrictionFacets(RestrictionFlags flags,
                                 object[] enumeration,
                                 int fractionDigits,
                                 int length,
                                 object maxExclusive,
                                 object maxInclusive,
                                 int maxLength,
                                 object minExclusive,
                                 object minInclusive,
                                 int minLength,
                                 string[] patterns,
                                 int totalDigits,
                                 XmlSchemaWhiteSpace whiteSpace)
        {
            hasValueFacets   = false;
            hasLexicalFacets = false;
            if ((flags & RestrictionFlags.Enumeration) != 0)
            {
                this.Enumeration = new ArrayList();
                foreach (object o in enumeration)
                {
                    this.Enumeration.Add(o);
                }

                hasValueFacets = true;
            }

            if ((flags & RestrictionFlags.FractionDigits) != 0)
            {
                this.FractionDigits = fractionDigits;
                hasValueFacets      = true;
            }

            if ((flags & RestrictionFlags.Length) != 0)
            {
                this.Length    = length;
                hasValueFacets = true;
            }

            if ((flags & RestrictionFlags.MaxExclusive) != 0)
            {
                this.MaxExclusive = maxExclusive;
                hasValueFacets    = true;
            }

            if ((flags & RestrictionFlags.MaxInclusive) != 0)
            {
                this.MaxInclusive = maxInclusive;
                hasValueFacets    = true;
            }

            if ((flags & RestrictionFlags.MaxLength) != 0)
            {
                this.MaxLength = maxLength;
                hasValueFacets = true;
            }

            if ((flags & RestrictionFlags.MinExclusive) != 0)
            {
                this.MinExclusive = minExclusive;
                hasValueFacets    = true;
            }

            if ((flags & RestrictionFlags.MinInclusive) != 0)
            {
                this.MinInclusive = minInclusive;
                hasValueFacets    = true;
            }

            if ((flags & RestrictionFlags.MinLength) != 0)
            {
                this.MinLength = minLength;
                hasValueFacets = true;
            }

            if ((flags & RestrictionFlags.Pattern) != 0)
            {
                CompilePatterns(patterns);
                hasLexicalFacets = true;
            }

            if ((flags & RestrictionFlags.TotalDigits) != 0)
            {
                this.TotalDigits = totalDigits;
                hasValueFacets   = true;
            }

            if ((flags & RestrictionFlags.WhiteSpace) != 0)
            {
                hasLexicalFacets = true;
                this.WhiteSpace  = whiteSpace;
            }

            this.Flags = flags;
        }
Пример #29
0
 private void CheckProhibitedFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode) {
     if ((validRestrictionFlags & flag) == 0) {
         throw new XmlSchemaException(errorCode, datatype.TypeCodeString, facet);
     }
 }
        internal override Exception CheckValueFacets(decimal value, SimpleTypeValidator type)
        {
            RestrictionFacets facets = type.RestrictionFacets;

            if (facets == null || !facets.HasValueFacets)
            {
                return(null);
            }

            //No need to check built-in type because CLR should've already done that

            RestrictionFlags  flags    = facets.Flags;
            XmlSchemaDatatype datatype = type.DataType;

            if ((flags & RestrictionFlags.Enumeration) != 0)
            {
                ArrayList enums = facets.Enumeration;


                if (!MatchEnumeration(value, enums, datatype))
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.Enumeration,
                                                       facets.Enumeration,
                                                       value));
                }
            }

            if ((flags & RestrictionFlags.FractionDigits) != 0)
            {
                Exception e = CheckTotalAndFractionDigits(value,
                                                          Constants.DecimalMaxPower,
                                                          facets.FractionDigits,
                                                          false,
                                                          true);

                if (e != null)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.FractionDigits, facets.FractionDigits, value));
                }
            }


            if ((flags & RestrictionFlags.MaxExclusive) != 0)
            {
                if (value >= (decimal)datatype.ChangeType(facets.MaxExclusive, typeof(decimal)))
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MaxExclusive, facets.MaxExclusive, value));
                }
            }

            if ((flags & RestrictionFlags.MaxInclusive) != 0)
            {
                if (value > (decimal)datatype.ChangeType(facets.MaxInclusive, typeof(decimal)))
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MaxInclusive, facets.MaxInclusive, value));
                }
            }

            if ((flags & RestrictionFlags.MinExclusive) != 0)
            {
                if (value <= (decimal)datatype.ChangeType(facets.MinExclusive, typeof(decimal)))
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MinExclusive, facets.MinExclusive, value));
                }
            }

            if ((flags & RestrictionFlags.MinInclusive) != 0)
            {
                if (value < (decimal)datatype.ChangeType(facets.MinInclusive, typeof(decimal)))
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MinInclusive, facets.MinInclusive, value));
                }
            }

            if ((flags & RestrictionFlags.TotalDigits) != 0)
            {
                Exception e = CheckTotalAndFractionDigits(value,
                                                          System.Convert.ToInt32(facets.TotalDigits),
                                                          0,
                                                          true,
                                                          false);

                if (e != null)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.TotalDigits, facets.TotalDigits, value));
                }
            }

            return(null);
        }
 public RestrictionFacets(RestrictionFlags flags, object[] enumeration, int fractionDigits, int length, object maxExclusive, object maxInclusive, int maxLength, object minExclusive, object minInclusive, int minLength, string[] patterns, int totalDigits, XmlSchemaWhiteSpace whiteSpace)
 {
     this.hasValueFacets   = false;
     this.hasLexicalFacets = false;
     if ((int)(flags & RestrictionFlags.Enumeration) != 0)
     {
         this.Enumeration = new ArrayList();
         object[] objArray = enumeration;
         for (int i = 0; i < (int)objArray.Length; i++)
         {
             object o = objArray[i];
             this.Enumeration.Add(o);
         }
         this.hasValueFacets = true;
     }
     if ((int)(flags & RestrictionFlags.FractionDigits) != 0)
     {
         this.FractionDigits = fractionDigits;
         this.hasValueFacets = true;
     }
     if ((int)(flags & RestrictionFlags.Length) != 0)
     {
         this.Length         = length;
         this.hasValueFacets = true;
     }
     if ((int)(flags & RestrictionFlags.MaxExclusive) != 0)
     {
         this.MaxExclusive   = maxExclusive;
         this.hasValueFacets = true;
     }
     if ((int)(flags & RestrictionFlags.MaxInclusive) != 0)
     {
         this.MaxInclusive   = maxInclusive;
         this.hasValueFacets = true;
     }
     if ((int)(flags & RestrictionFlags.MaxLength) != 0)
     {
         this.MaxLength      = maxLength;
         this.hasValueFacets = true;
     }
     if ((int)(flags & RestrictionFlags.MinExclusive) != 0)
     {
         this.MinExclusive   = minExclusive;
         this.hasValueFacets = true;
     }
     if ((int)(flags & RestrictionFlags.MinInclusive) != 0)
     {
         this.MinInclusive   = minInclusive;
         this.hasValueFacets = true;
     }
     if ((int)(flags & RestrictionFlags.MinLength) != 0)
     {
         this.MinLength      = minLength;
         this.hasValueFacets = true;
     }
     if ((int)(flags & RestrictionFlags.Pattern) != 0)
     {
         this.CompilePatterns(patterns);
         this.hasLexicalFacets = true;
     }
     if ((int)(flags & RestrictionFlags.TotalDigits) != 0)
     {
         this.TotalDigits    = totalDigits;
         this.hasValueFacets = true;
     }
     if ((int)(flags & RestrictionFlags.WhiteSpace) != 0)
     {
         this.hasLexicalFacets = true;
         this.WhiteSpace       = whiteSpace;
     }
     this.Flags = flags;
 }
        internal override Exception CheckValueFacets(object value, SimpleTypeValidator type)
        {
            RestrictionFacets facets = type.RestrictionFacets;

            if (facets == null || !facets.HasValueFacets)
            {
                return(null);
            }
            //Check for facets allowed on lists - Length, MinLength, MaxLength
            //value is a list
            IList     listValue = null;
            Exception e         = ListSimpleTypeValidator.ToList(value, ref listValue);

            if (e != null)
            {
                return(e);
            }

            int length = listValue.Count;

            XmlSchemaDatatype datatype = type.DataType;
            RestrictionFlags  flags    = facets.Flags;

            if ((flags & RestrictionFlags.Enumeration) != 0)
            {
                ArrayList enums = facets.Enumeration;

                if (!MatchEnumeration(value, enums, datatype))
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.Enumeration,
                                                       facets.Enumeration,
                                                       value));
                }
            }

            if ((flags & RestrictionFlags.Length) != 0)
            {
                if (length != facets.Length)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.Length, facets.Length, value));
                }
            }

            if ((flags & RestrictionFlags.MaxLength) != 0)
            {
                if (length > facets.MaxLength)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MaxLength, facets.MaxLength, value));
                }
            }

            if ((flags & RestrictionFlags.MinLength) != 0)
            {
                if (length < facets.MinLength)
                {
                    return(new LinqToXsdFacetException(RestrictionFlags.MinLength, facets.MinLength, value));
                }
            }

            return(null);
        }
Пример #33
0
 public LinqToXsdFacetException(RestrictionFlags flags,
                                object facetValue,
                                object value)
     : base(CreateMessage(flags.ToString(), facetValue, value))
 {
 }
Пример #34
0
 private void CheckFixedFlag(XmlSchemaFacet facet, RestrictionFlags fixedFlags, RestrictionFlags flag) {
     if ((fixedFlags & flag) != 0) {
         throw new XmlSchemaException(Res.Sch_FacetBaseFixed, facet);
     }
 }
Пример #35
0
 private void CheckProhibitedFlag(XmlSchemaFacet facet, RestrictionFlags validRestrictionFlags, RestrictionFlags flag, string errorCode) {
     if ((validRestrictionFlags & flag) == 0) {
         if(!valueType.Name.Equals("String[]"))
             throw new XmlSchemaException(errorCode, valueType.Name, facet);
         else
             throw new XmlSchemaException(errorCode, "IDREFS, NMTOKENS, ENTITIES", facet);
     }
 }
Пример #36
0
       public RestrictionFacets(RestrictionFlags flags,
                                object[] enumeration,
                                int fractionDigits,
                                int length,
                                object maxExclusive,
                                object maxInclusive,
                                int maxLength,
                                object minExclusive,
                                object minInclusive,
                                int minLength,
                                string[] patterns,
                                int totalDigits,
                                XmlSchemaWhiteSpace whiteSpace)
       {
            hasValueFacets = false;
            hasLexicalFacets = false;
           if ((flags & RestrictionFlags.Enumeration) != 0) {
               this.Enumeration = new ArrayList();
               foreach(object o in enumeration) {
                   this.Enumeration.Add(o);
               }
               hasValueFacets = true;
           }
           if ((flags & RestrictionFlags.FractionDigits) != 0) {
               this.FractionDigits = fractionDigits;
               hasValueFacets = true;
           }
           if ((flags & RestrictionFlags.Length) != 0) {
               this.Length = length;
               hasValueFacets = true;
           }
           if ((flags & RestrictionFlags.MaxExclusive) != 0) {
               this.MaxExclusive = maxExclusive;
               hasValueFacets = true;
           }
           if ((flags & RestrictionFlags.MaxInclusive) != 0) {
               this.MaxInclusive = maxInclusive;
               hasValueFacets = true;
           }
           if ((flags & RestrictionFlags.MaxLength) != 0) {
               this.MaxLength = maxLength;
               hasValueFacets = true;
           }
           if ((flags & RestrictionFlags.MinExclusive) != 0) {
               this.MinExclusive = minExclusive;
               hasValueFacets = true;
           }
           if ((flags & RestrictionFlags.MinInclusive) != 0) {
               this.MinInclusive = minInclusive;
               hasValueFacets = true;
           }
           if ((flags & RestrictionFlags.MinLength) != 0) {
               this.MinLength = minLength;
               hasValueFacets = true;
           }
           if ((flags & RestrictionFlags.Pattern) != 0) {
               CompilePatterns(patterns);
               hasLexicalFacets = true;
           }
           if ((flags & RestrictionFlags.TotalDigits) != 0) {
               this.TotalDigits = totalDigits;
               hasValueFacets = true;
           }
           if ((flags & RestrictionFlags.WhiteSpace) != 0) {
               hasLexicalFacets = true;
               this.WhiteSpace = whiteSpace;
           }

           this.Flags = flags;
           
       }
Пример #37
0
 public void compileFacets(XmlSchemaSimpleType simpleType)
 {
     XmlSchemaSimpleType type = simpleType;
     XmlSchemaSimpleType enumSimpleType = null; //simpletype that has most restricted enums.
     flags = 0;
     while (type != null && !String.Equals(type.QualifiedName.Namespace, Constants.XSD, StringComparison.Ordinal))
     {
         XmlSchemaSimpleTypeRestriction simpleTypeRestriction = type.Content as XmlSchemaSimpleTypeRestriction;
         if (simpleTypeRestriction != null)
         {
             foreach (XmlSchemaFacet facet in simpleTypeRestriction.Facets)
             {
                 if (facet is XmlSchemaMinLengthFacet)
                 {
                     if ((flags & RestrictionFlags.MinLength) == 0)
                     {
                         minLength = XmlConvert.ToInt32(facet.Value);
                         flags |= RestrictionFlags.MinLength;
                     }
                 }
                 else if (facet is XmlSchemaMaxLengthFacet)
                 {
                     if ((flags & RestrictionFlags.MaxLength) == 0)
                     {
                         maxLength = XmlConvert.ToInt32(facet.Value);
                         flags |= RestrictionFlags.MaxLength;
                     }
                 }
                 else if (facet is XmlSchemaLengthFacet)
                 {
                     if ((flags & RestrictionFlags.Length) == 0)
                     {
                         length = XmlConvert.ToInt32(facet.Value);
                         flags |= RestrictionFlags.Length;
                     }
                 }
                 else if (facet is XmlSchemaEnumerationFacet)
                 {
                     if (enumSimpleType == null)
                     {
                         enumerations = new ArrayList();
                         flags |= RestrictionFlags.Enumeration;
                         enumSimpleType = type;
                     }
                     else if (enumSimpleType != type)
                     {
                         continue;
                     }
                     enumerations.Add(type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null));
                 }
                 else if (facet is XmlSchemaPatternFacet)
                 {
                     if (patterns == null)
                     {
                         patterns = new ArrayList();
                         flags |= RestrictionFlags.Pattern;
                     }
                     patterns.Add(facet.Value);
                 }
                 else if (facet is XmlSchemaMaxInclusiveFacet)
                 {
                     if ((flags & RestrictionFlags.MaxInclusive) == 0)
                     {
                         maxInclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null);
                         flags |= RestrictionFlags.MaxInclusive;
                     }
                 }
                 else if (facet is XmlSchemaMaxExclusiveFacet)
                 {
                     if ((flags & RestrictionFlags.MaxExclusive) == 0)
                     {
                         maxExclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null);
                         flags |= RestrictionFlags.MaxExclusive;
                     }
                 }
                 else if (facet is XmlSchemaMinExclusiveFacet)
                 {
                     if ((flags & RestrictionFlags.MinExclusive) == 0)
                     {
                         minExclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null);
                         flags |= RestrictionFlags.MinExclusive;
                     }
                 }
                 else if (facet is XmlSchemaMinInclusiveFacet)
                 {
                     if ((flags & RestrictionFlags.MinInclusive) == 0)
                     {
                         minInclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null);
                         flags |= RestrictionFlags.MinInclusive;
                     }
                 }
                 else if (facet is XmlSchemaFractionDigitsFacet)
                 {
                     if ((flags & RestrictionFlags.FractionDigits) == 0)
                     {
                         fractionDigits = XmlConvert.ToInt32(facet.Value);
                         flags |= RestrictionFlags.FractionDigits;
                     }
                 }
                 else if (facet is XmlSchemaTotalDigitsFacet)
                 {
                     if ((flags & RestrictionFlags.TotalDigits) == 0)
                     {
                         totalDigits = XmlConvert.ToInt32(facet.Value);
                         flags |= RestrictionFlags.TotalDigits;
                     }
                 }
                 else if (facet is XmlSchemaWhiteSpaceFacet)
                 {
                     if ((flags & RestrictionFlags.WhiteSpace) == 0)
                     {
                         if (facet.Value == "preserve")
                         {
                             whiteSpace = XmlSchemaWhiteSpace.Preserve;
                         }
                         else if (facet.Value == "replace")
                         {
                             whiteSpace = XmlSchemaWhiteSpace.Replace;
                         }
                         else if (facet.Value == "collapse")
                         {
                             whiteSpace = XmlSchemaWhiteSpace.Collapse;
                         }
                         flags |= RestrictionFlags.WhiteSpace;
                     }
                 }
                 else
                 {
                     continue;
                 }
             }
         }
         type = type.BaseXmlSchemaType as XmlSchemaSimpleType;
     }
 }
Пример #38
0
 private void SetFlag(RestrictionFacets restriction, XmlSchemaFacet facet, RestrictionFlags flag) {
     restriction.Flags |= flag;
     if (facet.IsFixed) {
         restriction.FixedFlags |= flag;
     }
 }
Пример #39
0
 private void SetFlag(XmlSchemaFacet facet, RestrictionFlags flag) {
     derivedRestriction.Flags |= flag;
     if (facet.IsFixed) {
         derivedRestriction.FixedFlags |= flag;
     }
 }
Пример #40
0
 private void CheckDupFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode) {
     if ((derivedRestriction.Flags & flag) != 0) {
         throw new XmlSchemaException(errorCode, facet);
     }
 }
Пример #41
0
 private void SetFlag(RestrictionFacets restriction, RestrictionFlags fixedFlags, RestrictionFlags flag) {
     restriction.Flags |= flag;
     if ((fixedFlags & flag) != 0) {
         restriction.FixedFlags |= flag;
     }
 }
Пример #42
0
 private void SetFlag(RestrictionFlags flag) {
     derivedRestriction.Flags |= flag;
     if ((baseFixedFlags & flag) != 0) {
         derivedRestriction.FixedFlags |= flag;
     }
 }
Пример #43
0
 private void CheckValue(object value, XmlSchemaFacet facet, RestrictionFlags thisFlags) {
     if ((thisFlags & RestrictionFlags.MaxInclusive) != 0) {
         if (Compare(value, this.restriction.MaxInclusive) > 0) {
             throw new XmlSchemaException(Res.Sch_MaxInclusiveMismatch);
         }
     }
     if ((thisFlags & RestrictionFlags.MaxExclusive) != 0) {
         if (Compare(value, this.restriction.MaxExclusive) >= 0) {
             throw new XmlSchemaException(Res.Sch_MaxExclusiveMismatch);
         }
     }
     if ((thisFlags & RestrictionFlags.MinInclusive) != 0) {
         if (Compare(value, this.restriction.MinInclusive) < 0) {
             throw new XmlSchemaException(Res.Sch_MinInclusiveMismatch);
         }
     }
     if ((thisFlags & RestrictionFlags.MinExclusive) != 0) {
         if (Compare(value, this.restriction.MinExclusive) <= 0) {
             throw new XmlSchemaException(Res.Sch_MinExclusiveMismatch);
         }
     }
 }