internal void CheckWhitespaceFacets(ref string s, SimpleTypeValidator type, Xml.Schema.Linq.XmlSchemaWhiteSpace wsPattern) { Xml.Schema.Linq.RestrictionFacets restriction = type.RestrictionFacets; if (type.Variety == XmlSchemaDatatypeVariety.List) { s = s.Trim(); } else if (type.Variety == XmlSchemaDatatypeVariety.Atomic) { XmlSchemaDatatype datatype = type.DataType; if (datatype.GetBuiltInWSFacet() == Xml.Schema.Linq.XmlSchemaWhiteSpace.Collapse) { s = Xml.Schema.Linq.XmlComplianceUtil.NonCDataNormalize(s); } else if (datatype.GetBuiltInWSFacet() == Xml.Schema.Linq.XmlSchemaWhiteSpace.Replace) { s = Xml.Schema.Linq.XmlComplianceUtil.CDataNormalize(s); } else if (restriction != null & (int)(restriction.Flags & Xml.Schema.Linq.RestrictionFlags.WhiteSpace) != 0) { if (restriction.WhiteSpace == Xml.Schema.Linq.XmlSchemaWhiteSpace.Replace) { s = Xml.Schema.Linq.XmlComplianceUtil.CDataNormalize(s); } else if (restriction.WhiteSpace == Xml.Schema.Linq.XmlSchemaWhiteSpace.Collapse) { s = Xml.Schema.Linq.XmlComplianceUtil.NonCDataNormalize(s); } } } }
public static object ParseUnionValue(XAttribute attribute, SimpleTypeValidator typeDef) { object obj; obj = (attribute != null ? XTypedServices.ParseUnionValue(attribute.Value, attribute.Parent, attribute.Name, typeDef, ContainerType.Attribute) : null); return(obj); }
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); }
private static object ParseUnionValue(string value, XElement element, XName itemXName, SimpleTypeValidator typeDef, ContainerType containerType) { //Parse the string value based on the member types UnionSimpleTypeValidator unionDef = typeDef as UnionSimpleTypeValidator; Debug.Assert(unionDef != null); SimpleTypeValidator matchingType = null; object typedValue; Exception e = unionDef.TryParseValue(value, NameTable, new XNamespaceResolver(element), out matchingType, out typedValue); ListSimpleTypeValidator listType = matchingType as ListSimpleTypeValidator; if (listType != null) { SimpleTypeValidator itemType = listType.ItemType; return(new XListContent <object>((IList)typedValue, element, itemXName, containerType, itemType.DataType)); } Debug.Assert(e == null); return(typedValue); }
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); }
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 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); }
private void SetUnionCatchAll(object value, string propertyName, XTypedElement container, XName itemXName, SimpleTypeValidator typeDef, SchemaOrigin origin) { UnionSimpleTypeValidator unionDef = typeDef as UnionSimpleTypeValidator; Debug.Assert(unionDef != null); SimpleTypeValidator matchingType = null; object typedValue; Exception e = unionDef.TryParseValue(value, XTypedServices.NameTable, new XNamespaceResolver(container.GetUntyped()), out matchingType, out typedValue); if (e != null) { throw new LinqToXsdException(propertyName, e.Message); } else { if (matchingType is ListSimpleTypeValidator) { ListSimpleTypeValidator listType = matchingType as ListSimpleTypeValidator; switch (origin) { case SchemaOrigin.Element: SetListElement(itemXName, value, listType.ItemType.DataType); break; case SchemaOrigin.Text: SetListValue(value, listType.ItemType.DataType); break; case SchemaOrigin.Attribute: SetListAttribute(itemXName, value, listType.ItemType.DataType); break; default: break; } } else { switch (origin) { case SchemaOrigin.Element: SetElement(itemXName, value, matchingType.DataType); break; case SchemaOrigin.Text: SetValue(value, matchingType.DataType); break; case SchemaOrigin.Attribute: SetAttribute(itemXName, value, matchingType.DataType); break; default: break; } } } }
public ListSimpleTypeValidator(XmlSchemaSimpleType type, RestrictionFacets facets, SimpleTypeValidator itemType) : base(XmlSchemaDatatypeVariety.List, type, FacetsChecker.ListFacetsChecker, facets) { this.itemType = itemType; }
protected void SetUnionValue(object value, string propertyName, XTypedElement container, SimpleTypeValidator typeDef) { SetUnionCatchAll(value, propertyName, this, null, typeDef, SchemaOrigin.Text); }
public static object ParseUnionValue(XElement element, SimpleTypeValidator typeDef) { object obj; obj = (element != null ? XTypedServices.ParseUnionValue(element.Value, element, element.Name, typeDef, ContainerType.Element) : null); return(obj); }
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(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 virtual Exception TryParseValue(object value, NameTable nameTable, XNamespaceResolver resolver, out SimpleTypeValidator matchingType, out object typedValue) { throw new InvalidOperationException(); }
protected void SetUnionAttribute(object value, string propertyName, XTypedElement container, XName itemXName, SimpleTypeValidator typeDef) { SetUnionCatchAll(value, propertyName, container, itemXName, typeDef, SchemaOrigin.Attribute); }
public static object ParseUnionValue(XAttribute attribute, SimpleTypeValidator typeDef) { if (attribute == null) { return(null); } return(ParseUnionValue(attribute.Value, attribute.Parent, attribute.Name, typeDef, ContainerType.Attribute)); }
internal virtual Exception CheckLexicalFacets(ref string parsedString, SimpleTypeValidator type, ArrayList patterns, XmlSchemaWhiteSpace wsPattern) { CheckWhitespaceFacets(ref parsedString, type, wsPattern); return(CheckPatternFacets(patterns, parsedString)); }
public static object ParseUnionValue(XElement element, SimpleTypeValidator typeDef) { if (element == null) { return(null); } return(ParseUnionValue(element.Value, element, element.Name, typeDef, ContainerType.Element)); }
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 TryParseValue(object value, NameTable nameTable, XNamespaceResolver resolver, out SimpleTypeValidator matchingType, out object typedValue) { //Only accepts string and IEnumerable Exception e = null; typedValue = null; matchingType = null; if (RestrictionFacets != null && RestrictionFacets.HasLexicalFacets) { string parsedString = null; e = TryParseString(value, nameTable, resolver, out parsedString); if (e == null) { e = facetsChecker.CheckLexicalFacets(ref parsedString, value, nameTable, resolver, this); } } if (e == null) { e = facetsChecker.CheckValueFacets(value, this); } if (e != null) { return(e); } //Check item type level IList listItems = null; e = ToList(value, ref listItems); if (e != null) { return(e); } foreach (object listItem in listItems) { object typedItemValue = null; SimpleTypeValidator itemMatchingType = null; e = itemType.TryParseValue(listItem, nameTable, resolver, out itemMatchingType, out typedItemValue); if (e != null) { return(e); } } //Passed all the restriction checks typedValue = listItems; matchingType = this; return(null); }
internal override Exception TryParseValue(object value, NameTable nameTable, XNamespaceResolver resolver, out SimpleTypeValidator matchingType, out object typedValue) { typedValue = null; matchingType = null; if (value == null) { return(new ArgumentNullException("Argument value should not be null.")); } object typedMemberValue = null; foreach (SimpleTypeValidator memberType in memberTypes) { if (memberType.TryParseValue(value, nameTable, resolver, out matchingType, out typedMemberValue) == null) { break; } } if (typedMemberValue == null) { return(new UnionMemberTypeNotFoundException(value, this)); } else { Exception e = null; if (RestrictionFacets != null && RestrictionFacets.HasLexicalFacets) { string parsedString = null; e = matchingType.TryParseString(value, nameTable, resolver, out parsedString); if (e == null) { e = facetsChecker.CheckLexicalFacets(ref parsedString, value, nameTable, resolver, this); } } if (e == null) { e = facetsChecker.CheckValueFacets(typedMemberValue, this); } if (e != null) { return(e); } else { typedValue = typedMemberValue; return(null); } } }
{ //hexBinary & Base64Binary internal override Exception CheckValueFacets(object value, SimpleTypeValidator type) { if (type.RestrictionFacets == null || !type.RestrictionFacets.HasValueFacets) { return(null); } byte[] byteArrayValue = (byte[])value; return(CheckValueFacets(byteArrayValue, type)); }
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); }
internal override Exception CheckValueFacets(object value, SimpleTypeValidator type) { if (type.RestrictionFacets == null || !type.RestrictionFacets.HasValueFacets) { return(null); } XmlSchemaDatatype datatype = type.DataType; XmlQualifiedName qualifiedNameValue = (XmlQualifiedName)datatype.ChangeType(value, typeof(XmlQualifiedName)); return(CheckValueFacets(qualifiedNameValue, type)); }
internal override Exception CheckValueFacets(object value, SimpleTypeValidator type) { if (type.RestrictionFacets == null || !type.RestrictionFacets.HasValueFacets) { return(null); } XmlSchemaDatatype datatype = type.DataType; TimeSpan timeSpanValue = (TimeSpan)datatype.ChangeType(value, typeof(TimeSpan)); return(CheckValueFacets(timeSpanValue, type)); }
private static List <string> GetMemberTypeCodes(UnionSimpleTypeValidator typeDef) { List <string> codes = new List <string>(); SimpleTypeValidator[] memberTypes = typeDef.MemberTypes; for (int i = 0; i < (int)memberTypes.Length; i++) { SimpleTypeValidator type = memberTypes[i]; codes.Add(type.DataType.TypeCode.ToString()); } return(codes); }
protected void SetElementWithValidation(XName name, object value, string propertyName, SimpleTypeValidator typeDef) { object typedValue = null; SimpleTypeValidator matchingType = null; Exception e = typeDef.TryParseValue(value, XTypedServices.NameTable, new XNamespaceResolver(this.GetUntyped()), out matchingType, out typedValue); if (e != null) { throw new LinqToXsdException(propertyName, e.Message); } this.SetElement(name, typedValue, typeDef.DataType); }
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); }
protected void SetElementWithValidation(XName name, object value, string propertyName, SimpleTypeValidator typeDef) { //Set value after validation object typedValue = null; SimpleTypeValidator matchingType = null; Exception e = typeDef.TryParseValue(value, XTypedServices.NameTable, new XNamespaceResolver(this.GetUntyped()), out matchingType, out typedValue); if (e == null) { SetElement(name, typedValue, typeDef.DataType); } else { throw new LinqToXsdException(propertyName, e.Message); } }
//Method for setting values of a simple typed root element protected void SetValueWithValidation(object value, string propertyName, SimpleTypeValidator simpleType) { //Set value after validation Debug.Assert((value as XTypedElement) == null, "Cannot set an XTypedElement value as type of simple typed root element"); object typedValue = null; SimpleTypeValidator matchingType = null; Exception e = simpleType.TryParseValue(value, XTypedServices.NameTable, new XNamespaceResolver(this.GetUntyped()), out matchingType, out typedValue); if (e == null) { SetValue(typedValue, simpleType.DataType); } else { throw new LinqToXsdException(propertyName, e.Message); } }
protected void SetListAttributeWithValidation(XName name, object value, string propertyName, SimpleTypeValidator typeDef) { object typedValue; SimpleTypeValidator matchingType = null; Exception e = typeDef.TryParseValue(value, XTypedServices.NameTable, new XNamespaceResolver(this.Untyped), out matchingType, out typedValue); if (e != null) { throw new LinqToXsdException(propertyName, e.Message); } ListSimpleTypeValidator listDef = typeDef as ListSimpleTypeValidator; Debug.Assert(listDef != null); SetListAttribute(name, value, listDef.ItemType.DataType); }
internal override Exception TryParseValue(object value, NameTable nameTable, XNamespaceResolver resolver, out SimpleTypeValidator matchingType, out object typedValue) { typedValue = null; matchingType = null; if (value == null) return new ArgumentNullException("Argument value should not be null."); object typedMemberValue = null; foreach (SimpleTypeValidator memberType in memberTypes) { if (memberType.TryParseValue(value, nameTable, resolver, out matchingType, out typedMemberValue) == null) { break; } } if (typedMemberValue == null) { return new UnionMemberTypeNotFoundException(value, this); } else { Exception e = null; if (RestrictionFacets != null && RestrictionFacets.HasLexicalFacets) { string parsedString = null; e = matchingType.TryParseString(value, nameTable, resolver, out parsedString); if (e == null) e = facetsChecker.CheckLexicalFacets(ref parsedString, value, nameTable, resolver, this); } if (e == null) e = facetsChecker.CheckValueFacets(typedMemberValue, this); if (e != null) return e; else { typedValue = typedMemberValue; return null; } } }
internal override Exception TryParseValue(object value, NameTable nameTable, XNamespaceResolver resolver, out SimpleTypeValidator matchingType, out object typedValue) { //Only accepts string and IEnumerable Exception e = null; typedValue = null; matchingType = null; if (RestrictionFacets != null && RestrictionFacets.HasLexicalFacets) { string parsedString = null; e = TryParseString(value, nameTable, resolver, out parsedString); if (e == null) e = facetsChecker.CheckLexicalFacets(ref parsedString, value, nameTable, resolver, this); } if (e == null) e = facetsChecker.CheckValueFacets(value, this); if (e != null) return e; //Check item type level IList listItems = null; e = ToList(value, ref listItems); if (e!=null) return e; foreach (object listItem in listItems) { object typedItemValue = null; SimpleTypeValidator itemMatchingType = null; e = itemType.TryParseValue(listItem, nameTable, resolver, out itemMatchingType, out typedItemValue); if (e != null) return e; } //Passed all the restriction checks typedValue = listItems; matchingType = this; return null; }
internal override Exception TryParseValue(object value, NameTable nameTable, XNamespaceResolver resolver, out SimpleTypeValidator matchingType, out object typedValue) { Exception e = TryMatchAtomicType(value, nameTable, resolver); matchingType = null; typedValue = null; if (e != null) return e; try { if (RestrictionFacets != null && RestrictionFacets.HasLexicalFacets) { string parsedString = null; e = TryParseString(value, nameTable, resolver, out parsedString); if (e==null) e = facetsChecker.CheckLexicalFacets(ref parsedString, value, nameTable, resolver, this); } if (e == null) e = facetsChecker.CheckValueFacets(value, this); if (e == null) { matchingType = this; typedValue = DataType.ChangeType(value, this.DataType.ValueType); } return e; } catch(Exception ee) { return ee; } }
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, 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 override Exception CheckValueFacets(object value, SimpleTypeValidator type) { if (type.RestrictionFacets == null || !type.RestrictionFacets.HasValueFacets) { return null; } XmlSchemaDatatype datatype = type.DataType; string stringValue = null; if (type.DataType.TypeCode == XmlTypeCode.AnyUri) { stringValue = ((Uri)datatype.ChangeType(value, typeof(Uri))).OriginalString; } else { stringValue = (string)datatype.ChangeType(value, XTypedServices.typeOfString); } return CheckValueFacets(stringValue, type); }
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; }
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; }
{ //hexBinary & Base64Binary internal override Exception CheckValueFacets(object value, SimpleTypeValidator type) { if (type.RestrictionFacets == null || !type.RestrictionFacets.HasValueFacets) { return null; } byte[] byteArrayValue = (byte[])value; return CheckValueFacets(byteArrayValue, type); }
private void SetUnionCatchAll( object value, string propertyName, XTypedElement container, XName itemXName, SimpleTypeValidator typeDef, SchemaOrigin origin) { UnionSimpleTypeValidator unionDef = typeDef as UnionSimpleTypeValidator; Debug.Assert(unionDef != null); SimpleTypeValidator matchingType = null; object typedValue; Exception e = unionDef.TryParseValue( value, XTypedServices.NameTable, new XNamespaceResolver(container.GetUntyped()), out matchingType, out typedValue); if (e != null) { throw new LinqToXsdException(propertyName, e.Message); } else { if (matchingType is ListSimpleTypeValidator) { ListSimpleTypeValidator listType = matchingType as ListSimpleTypeValidator; switch (origin) { case SchemaOrigin.Element: SetListElement(itemXName, value, listType.ItemType.DataType); break; case SchemaOrigin.Text: SetListValue(value, listType.ItemType.DataType); break; case SchemaOrigin.Attribute: SetListAttribute(itemXName, value, listType.ItemType.DataType); break; default: break; } } else { switch (origin) { case SchemaOrigin.Element: SetElement(itemXName, value, matchingType.DataType); break; case SchemaOrigin.Text: SetValue(value, matchingType.DataType); break; case SchemaOrigin.Attribute: SetAttribute(itemXName, value, matchingType.DataType); break; default: break; } } } }
protected void SetUnionElement( object value, string propertyName, XTypedElement container, XName itemXName, SimpleTypeValidator typeDef) { SetUnionCatchAll( value, propertyName, container, itemXName, typeDef, SchemaOrigin.Element); }
internal override Exception CheckValueFacets(object value, SimpleTypeValidator type) { if (type.RestrictionFacets == null || !type.RestrictionFacets.HasValueFacets) { return null; } XmlSchemaDatatype datatype = type.DataType; TimeSpan timeSpanValue = (TimeSpan)datatype.ChangeType(value, typeof(TimeSpan)); return CheckValueFacets(timeSpanValue, type); }
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 virtual Exception CheckValueFacets(TimeSpan value, SimpleTypeValidator type) { return null; }
internal override Exception CheckValueFacets(string value, SimpleTypeValidator type) { return CheckValueFacets(value, type, true); }
internal virtual Exception CheckValueFacets(XmlQualifiedName value, SimpleTypeValidator type) { return null; }
internal override Exception CheckValueFacets(object value, SimpleTypeValidator type) { if (type.RestrictionFacets == null || !type.RestrictionFacets.HasValueFacets) { return null; } XmlSchemaDatatype datatype = type.DataType; XmlQualifiedName qualifiedNameValue = (XmlQualifiedName)datatype.ChangeType(value, typeof(XmlQualifiedName)); return CheckValueFacets(qualifiedNameValue, type); }
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 virtual Exception CheckLexicalFacets(ref string parsedString, SimpleTypeValidator type, ArrayList patterns, XmlSchemaWhiteSpace wsPattern) { CheckWhitespaceFacets(ref parsedString, type, wsPattern); return CheckPatternFacets(patterns, parsedString); }
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; }
public UnionSimpleTypeValidator(XmlSchemaSimpleType type, RestrictionFacets facets, SimpleTypeValidator[] memberTypes) : base(XmlSchemaDatatypeVariety.Union, type, FacetsChecker.UnionFacetsChecker, facets) { this.memberTypes = memberTypes; }
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; }
protected void SetListValueWithValidation(object value, string propertyName, SimpleTypeValidator typeDef) { //This is for list type, will be saved as space-separated strings ListSimpleTypeValidator listDef = typeDef as ListSimpleTypeValidator; Debug.Assert(listDef != null); object typedValue; SimpleTypeValidator matchingType = null; Exception e = typeDef.TryParseValue(value, XTypedServices.NameTable, new XNamespaceResolver(this.GetUntyped()), out matchingType, out typedValue); if (e == null) { SetListValue(value, matchingType.DataType); } else { throw new LinqToXsdException(propertyName, e.Message); } }
internal override Exception CheckValueFacets(float value, SimpleTypeValidator type) { double doubleValue = (double)value; return CheckValueFacets(doubleValue, type); }