Ejemplo n.º 1
0
        internal override Exception CheckValueFacets(object value, SimpleTypeValidator type)
        {
            Exception linqToXsdFacetException;

            Xml.Schema.Linq.RestrictionFacets facets = type.RestrictionFacets;
            if ((facets == null ? false : facets.HasValueFacets))
            {
                Xml.Schema.Linq.RestrictionFlags flags = facets.Flags;
                XmlSchemaDatatype datatype             = type.DataType;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Enumeration) != 0)
                {
                    if (!this.MatchEnumeration(value, facets.Enumeration, datatype))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.Enumeration, facets.Enumeration, value);
                        return(linqToXsdFacetException);
                    }
                }
                linqToXsdFacetException = null;
            }
            else
            {
                linqToXsdFacetException = null;
            }
            return(linqToXsdFacetException);
        }
Ejemplo n.º 2
0
        internal override Exception CheckValueFacets(object value, SimpleTypeValidator type)
        {
            Exception linqToXsdFacetException;

            Xml.Schema.Linq.RestrictionFacets facets = type.RestrictionFacets;
            if ((facets == null ? false : facets.HasValueFacets))
            {
                IList     listValue = null;
                Exception e         = ListSimpleTypeValidator.ToList(value, ref listValue);
                if (e == null)
                {
                    int length = listValue.Count;
                    XmlSchemaDatatype datatype             = type.DataType;
                    Xml.Schema.Linq.RestrictionFlags flags = facets.Flags;
                    if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Enumeration) != 0)
                    {
                        if (!this.MatchEnumeration(value, facets.Enumeration, datatype))
                        {
                            linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.Enumeration, facets.Enumeration, value);
                            return(linqToXsdFacetException);
                        }
                    }
                    if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Length) != 0)
                    {
                        if (length != facets.Length)
                        {
                            linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.Length, (object)facets.Length, value);
                            return(linqToXsdFacetException);
                        }
                    }
                    if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxLength) != 0)
                    {
                        if (length > facets.MaxLength)
                        {
                            linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxLength, (object)facets.MaxLength, value);
                            return(linqToXsdFacetException);
                        }
                    }
                    if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinLength) != 0)
                    {
                        if (length < facets.MinLength)
                        {
                            linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MinLength, (object)facets.MinLength, value);
                            return(linqToXsdFacetException);
                        }
                    }
                    linqToXsdFacetException = null;
                }
                else
                {
                    linqToXsdFacetException = e;
                }
            }
            else
            {
                linqToXsdFacetException = null;
            }
            return(linqToXsdFacetException);
        }
        internal Exception CheckValueFacets(string value, SimpleTypeValidator type, bool verifyUri)
        {
            Exception linqToXsdFacetException;
            int       length = value.Length;

            Xml.Schema.Linq.RestrictionFacets facets = type.RestrictionFacets;
            if (facets != null)
            {
                Xml.Schema.Linq.RestrictionFlags flags = facets.Flags;
                XmlSchemaDatatype datatype             = type.DataType;
                Exception         exception            = this.CheckBuiltInFacets(value, datatype.TypeCode, verifyUri);
                if (exception == null)
                {
                    if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Enumeration) != 0)
                    {
                        if (!this.MatchEnumeration(value, facets.Enumeration, datatype))
                        {
                            linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.Enumeration, facets.Enumeration, value);
                            return(linqToXsdFacetException);
                        }
                    }
                    if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Length) != 0)
                    {
                        if (length != facets.Length)
                        {
                            linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.Length, (object)facets.Length, value);
                            return(linqToXsdFacetException);
                        }
                    }
                    if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxLength) != 0)
                    {
                        if (length > facets.MaxLength)
                        {
                            linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxLength, (object)facets.MaxLength, value);
                            return(linqToXsdFacetException);
                        }
                    }
                    if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinLength) != 0)
                    {
                        if (length < facets.MinLength)
                        {
                            linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MinLength, (object)facets.MinLength, value);
                            return(linqToXsdFacetException);
                        }
                    }
                    linqToXsdFacetException = null;
                }
                else
                {
                    linqToXsdFacetException = exception;
                }
            }
            else
            {
                linqToXsdFacetException = null;
            }
            return(linqToXsdFacetException);
        }
Ejemplo n.º 4
0
        internal override Exception CheckValueFacets(TimeSpan value, SimpleTypeValidator type)
        {
            Exception linqToXsdFacetException;

            Xml.Schema.Linq.RestrictionFacets facets = type.RestrictionFacets;
            if ((facets == null ? false : facets.HasValueFacets))
            {
                Xml.Schema.Linq.RestrictionFlags flags = facets.Flags;
                XmlSchemaDatatype datatype             = type.DataType;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Enumeration) != 0)
                {
                    if (!this.MatchEnumeration(value, facets.Enumeration, datatype))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.Enumeration, facets.Enumeration, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxInclusive) != 0)
                {
                    if (TimeSpan.Compare(value, (TimeSpan)datatype.ChangeType(facets.MaxInclusive, typeof(TimeSpan))) > 0)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxInclusive, facets.MaxInclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxExclusive) != 0)
                {
                    if (TimeSpan.Compare(value, (TimeSpan)datatype.ChangeType(facets.MaxExclusive, typeof(TimeSpan))) >= 0)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxExclusive, facets.MaxExclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinInclusive) != 0)
                {
                    if (TimeSpan.Compare(value, (TimeSpan)datatype.ChangeType(facets.MinInclusive, typeof(TimeSpan))) < 0)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxExclusive, facets.MinInclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinExclusive) != 0)
                {
                    if (TimeSpan.Compare(value, (TimeSpan)datatype.ChangeType(facets.MinExclusive, typeof(TimeSpan))) <= 0)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxExclusive, facets.MinExclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                linqToXsdFacetException = null;
            }
            else
            {
                linqToXsdFacetException = null;
            }
            return(linqToXsdFacetException);
        }
        internal override Exception CheckValueFacets(XmlQualifiedName value, SimpleTypeValidator type)
        {
            Exception linqToXsdFacetException;

            Xml.Schema.Linq.RestrictionFacets facets = type.RestrictionFacets;
            if (!(facets == null ? false : facets.HasValueFacets))
            {
                linqToXsdFacetException = null;
            }
            else if (facets != null)
            {
                Xml.Schema.Linq.RestrictionFlags flags = facets.Flags;
                XmlSchemaDatatype datatype             = type.DataType;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Enumeration) != 0)
                {
                    if (!this.MatchEnumeration(value, facets.Enumeration, datatype))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.Enumeration, facets.Enumeration, value);
                        return(linqToXsdFacetException);
                    }
                }
                int length = value.ToString().Length;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Length) != 0)
                {
                    if (length != facets.Length)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.Length, (object)facets.Length, value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxLength) != 0)
                {
                    if (length > facets.MaxLength)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxLength, (object)facets.MaxLength, value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinLength) != 0)
                {
                    if (length < facets.MinLength)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MinLength, (object)facets.MinLength, value);
                        return(linqToXsdFacetException);
                    }
                }
                linqToXsdFacetException = null;
            }
            else
            {
                linqToXsdFacetException = null;
            }
            return(linqToXsdFacetException);
        }
Ejemplo n.º 6
0
        internal Exception CheckPatternFacets(ArrayList patterns, string value)
        {
            Exception linqToXsdFacetException;

            if (patterns != null)
            {
                foreach (object pattern in patterns)
                {
                    Regex regex = pattern as Regex;
                    Debug.Assert(regex != null);
                    if (regex.IsMatch(value))
                    {
                        linqToXsdFacetException = null;
                        return(linqToXsdFacetException);
                    }
                }
                linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.Pattern, patterns, value);
            }
            else
            {
                linqToXsdFacetException = null;
            }
            return(linqToXsdFacetException);
        }
        internal override Exception CheckValueFacets(decimal value, SimpleTypeValidator type)
        {
            Exception linqToXsdFacetException;

            Xml.Schema.Linq.RestrictionFacets facets = type.RestrictionFacets;
            if ((facets == null ? false : facets.HasValueFacets))
            {
                Xml.Schema.Linq.RestrictionFlags flags = facets.Flags;
                XmlSchemaDatatype datatype             = type.DataType;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Enumeration) != 0)
                {
                    if (!this.MatchEnumeration(value, facets.Enumeration, datatype))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.Enumeration, facets.Enumeration, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.FractionDigits) != 0)
                {
                    if (base.CheckTotalAndFractionDigits(value, 29, facets.FractionDigits, false, true) != null)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.FractionDigits, (object)facets.FractionDigits, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxExclusive) != 0)
                {
                    if (value >= (decimal)datatype.ChangeType(facets.MaxExclusive, typeof(decimal)))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxExclusive, facets.MaxExclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxInclusive) != 0)
                {
                    if (value > (decimal)datatype.ChangeType(facets.MaxInclusive, typeof(decimal)))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxInclusive, facets.MaxInclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinExclusive) != 0)
                {
                    if (value <= (decimal)datatype.ChangeType(facets.MinExclusive, typeof(decimal)))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MinExclusive, facets.MinExclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinInclusive) != 0)
                {
                    if (value < (decimal)datatype.ChangeType(facets.MinInclusive, typeof(decimal)))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MinInclusive, facets.MinInclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.TotalDigits) != 0)
                {
                    if (base.CheckTotalAndFractionDigits(value, Convert.ToInt32(facets.TotalDigits), 0, true, false) != null)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.TotalDigits, (object)facets.TotalDigits, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                linqToXsdFacetException = null;
            }
            else
            {
                linqToXsdFacetException = null;
            }
            return(linqToXsdFacetException);
        }