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 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 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);
        }
        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));
        }
 public UnionSimpleTypeValidator(XmlSchemaSimpleType type,
                                 RestrictionFacets facets,
                                 SimpleTypeValidator[] memberTypes)
     : base(XmlSchemaDatatypeVariety.Union, type, FacetsChecker.UnionFacetsChecker, facets)
 {
     this.memberTypes = memberTypes;
 }
        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);
        }
 public ListSimpleTypeValidator(XmlSchemaSimpleType type,
                                RestrictionFacets facets,
                                SimpleTypeValidator itemType)
     : base(XmlSchemaDatatypeVariety.List, type, FacetsChecker.ListFacetsChecker, facets)
 {
     this.itemType = itemType;
 }
 public AtomicSimpleTypeValidator(XmlSchemaSimpleType type,
                                  RestrictionFacets facets)
     : base(XmlSchemaDatatypeVariety.Atomic,
            type,
            FacetsChecker.GetFacetsChecker(type.Datatype.TypeCode),
            facets)
 {
 }
 internal SimpleTypeValidator(XmlSchemaDatatypeVariety variety,
                              XmlSchemaSimpleType type,
                              FacetsChecker facetsChecker,
                              RestrictionFacets facets)
 {
     this.restrictionFacets = facets;
     this.facetsChecker     = facetsChecker;
     this.dataType          = type.Datatype;
     this.variety           = variety;
 }
Exemple #10
0
        internal void CheckWhitespaceFacets(ref string s,
                                            SimpleTypeValidator type,
                                            XmlSchemaWhiteSpace wsPattern)
        {
            // before parsing, check whitespace facet
            RestrictionFacets restriction = type.RestrictionFacets;

            if (type.Variety == XmlSchemaDatatypeVariety.List)
            {
                s = s.Trim();
                return;
            }
            else if (type.Variety == XmlSchemaDatatypeVariety.Atomic)
            {
                XmlSchemaDatatype datatype = type.DataType;
                if (datatype.GetBuiltInWSFacet() == XmlSchemaWhiteSpace.Collapse)
                {
                    s = XmlComplianceUtil.NonCDataNormalize(s);
                }
                else if (datatype.GetBuiltInWSFacet() == XmlSchemaWhiteSpace.Replace)
                {
                    s = XmlComplianceUtil.CDataNormalize(s);
                }
                else if (restriction != null & (restriction.Flags & RestrictionFlags.WhiteSpace) != 0)
                {
                    //Restriction has whitespace facet specified
                    if (restriction.WhiteSpace == XmlSchemaWhiteSpace.Replace)
                    {
                        s = XmlComplianceUtil.CDataNormalize(s);
                    }
                    else if (restriction.WhiteSpace == XmlSchemaWhiteSpace.Collapse)
                    {
                        s = XmlComplianceUtil.NonCDataNormalize(s);
                    }
                }
            }

            return;
        }
        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);
        }
        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);
        }