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 override Exception TryParseValue(object value, NameTable nameTable, XNamespaceResolver resolver, out SimpleTypeValidator matchingType, out object typedValue) { Exception exception; Exception e = null; typedValue = null; matchingType = null; if ((base.RestrictionFacets == null ? false : base.RestrictionFacets.HasLexicalFacets)) { string parsedString = null; e = this.TryParseString(value, nameTable, resolver, out parsedString); if (e == null) { e = this.facetsChecker.CheckLexicalFacets(ref parsedString, value, nameTable, resolver, this); } } if (e == null) { e = this.facetsChecker.CheckValueFacets(value, this); } if (e == null) { IList listItems = null; e = ListSimpleTypeValidator.ToList(value, ref listItems); if (e == null) { foreach (object listItem in listItems) { object typedItemValue = null; SimpleTypeValidator itemMatchingType = null; e = this.itemType.TryParseValue(listItem, nameTable, resolver, out itemMatchingType, out typedItemValue); if (e != null) { exception = e; return(exception); } } typedValue = listItems; matchingType = this; exception = null; } else { exception = e; } } else { exception = e; } return(exception); }
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); }