internal virtual Exception CheckLexicalFacets(ref string parsedString, object value, NameTable nameTable, XNamespaceResolver resolver, SimpleTypeValidator type) { Exception exception; Xml.Schema.Linq.RestrictionFacets facets = type.RestrictionFacets; if ((facets == null ? false : facets.HasLexicalFacets)) { Xml.Schema.Linq.RestrictionFlags flags = facets.Flags; Xml.Schema.Linq.XmlSchemaWhiteSpace wsPattern = Xml.Schema.Linq.XmlSchemaWhiteSpace.Collapse; if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.WhiteSpace) != 0) { if (facets.WhiteSpace == Xml.Schema.Linq.XmlSchemaWhiteSpace.Collapse) { wsPattern = Xml.Schema.Linq.XmlSchemaWhiteSpace.Collapse; } else if (facets.WhiteSpace == Xml.Schema.Linq.XmlSchemaWhiteSpace.Preserve) { wsPattern = Xml.Schema.Linq.XmlSchemaWhiteSpace.Preserve; } } exception = this.CheckLexicalFacets(ref parsedString, type, facets.Patterns, wsPattern); } else { exception = null; } return(exception); }
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); }
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); }
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); }
public void compileFacets(XmlSchemaSimpleType simpleType) { XmlSchemaSimpleType type = simpleType; XmlSchemaSimpleType enumSimpleType = null; this.flags = (Xml.Schema.Linq.RestrictionFlags) 0; while (true) { if ((type == null ? true : string.Equals(type.QualifiedName.Namespace, "http://www.w3.org/2001/XMLSchema", StringComparison.Ordinal))) { break; } XmlSchemaSimpleTypeRestriction simpleTypeRestriction = type.Content as XmlSchemaSimpleTypeRestriction; if (simpleTypeRestriction != null) { foreach (XmlSchemaFacet facet in simpleTypeRestriction.Facets) { if (facet is XmlSchemaMinLengthFacet) { if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.MinLength) == 0) { this.minLength = XmlConvert.ToInt32(facet.Value); this.flags |= Xml.Schema.Linq.RestrictionFlags.MinLength; } } else if (facet is XmlSchemaMaxLengthFacet) { if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.MaxLength) == 0) { this.maxLength = XmlConvert.ToInt32(facet.Value); this.flags |= Xml.Schema.Linq.RestrictionFlags.MaxLength; } } else if (facet is XmlSchemaLengthFacet) { if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.Length) == 0) { this.length = XmlConvert.ToInt32(facet.Value); this.flags |= Xml.Schema.Linq.RestrictionFlags.Length; } } else if (facet is XmlSchemaEnumerationFacet) { if (enumSimpleType == null) { this.enumerations = new ArrayList(); this.flags |= Xml.Schema.Linq.RestrictionFlags.Enumeration; enumSimpleType = type; } else if (enumSimpleType != type) { continue; } this.enumerations.Add(type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null)); } else if (facet is XmlSchemaPatternFacet) { if (this.patterns == null) { this.patterns = new ArrayList(); this.flags |= Xml.Schema.Linq.RestrictionFlags.Pattern; } this.patterns.Add(facet.Value); } else if (facet is XmlSchemaMaxInclusiveFacet) { if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.MaxInclusive) == 0) { this.maxInclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null); this.flags |= Xml.Schema.Linq.RestrictionFlags.MaxInclusive; } } else if (facet is XmlSchemaMaxExclusiveFacet) { if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.MaxExclusive) == 0) { this.maxExclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null); this.flags |= Xml.Schema.Linq.RestrictionFlags.MaxExclusive; } } else if (facet is XmlSchemaMinExclusiveFacet) { if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.MinExclusive) == 0) { this.minExclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null); this.flags |= Xml.Schema.Linq.RestrictionFlags.MinExclusive; } } else if (facet is XmlSchemaMinInclusiveFacet) { if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.MinInclusive) == 0) { this.minInclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null); this.flags |= Xml.Schema.Linq.RestrictionFlags.MinInclusive; } } else if (facet is XmlSchemaFractionDigitsFacet) { if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.FractionDigits) == 0) { this.fractionDigits = XmlConvert.ToInt32(facet.Value); this.flags |= Xml.Schema.Linq.RestrictionFlags.FractionDigits; } } else if (facet is XmlSchemaTotalDigitsFacet) { if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.TotalDigits) == 0) { this.totalDigits = XmlConvert.ToInt32(facet.Value); this.flags |= Xml.Schema.Linq.RestrictionFlags.TotalDigits; } } else if (!(facet is XmlSchemaWhiteSpaceFacet)) { continue; } else if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.WhiteSpace) == 0) { if (facet.Value == "preserve") { this.whiteSpace = Xml.Schema.Linq.XmlSchemaWhiteSpace.Preserve; } else if (facet.Value == "replace") { this.whiteSpace = Xml.Schema.Linq.XmlSchemaWhiteSpace.Replace; } else if (facet.Value == "collapse") { this.whiteSpace = Xml.Schema.Linq.XmlSchemaWhiteSpace.Collapse; } this.flags |= Xml.Schema.Linq.RestrictionFlags.WhiteSpace; } } } type = type.BaseXmlSchemaType as XmlSchemaSimpleType; } }
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); }