public override object ValueAs(Type type, IXmlNamespaceResolver nsResolver) { XmlValueConverter valueConverter = this.xmlType.ValueConverter; if ((type == typeof(XPathItem)) || (type == typeof(XmlAtomicValue))) { return(this); } if (this.objVal == null) { switch (this.clrType) { case TypeCode.Int32: return(valueConverter.ChangeType(this.unionVal.i32Val, type)); case TypeCode.Int64: return(valueConverter.ChangeType(this.unionVal.i64Val, type)); case TypeCode.Boolean: return(valueConverter.ChangeType(this.unionVal.boolVal, type)); case TypeCode.Double: return(valueConverter.ChangeType(this.unionVal.dblVal, type)); case TypeCode.DateTime: return(valueConverter.ChangeType(this.unionVal.dtVal, type)); } } return(valueConverter.ChangeType(this.objVal, type, nsResolver)); }
public override object ValueAs(Type type, IXmlNamespaceResolver?nsResolver) { XmlValueConverter valueConverter = _xmlType.ValueConverter; if (type == typeof(XPathItem) || type == typeof(XmlAtomicValue)) { return(this); } if (_objVal == null) { switch (_clrType) { case TypeCode.Boolean: return(valueConverter.ChangeType(_unionVal.boolVal, type)); case TypeCode.Int32: return(valueConverter.ChangeType(_unionVal.i32Val, type)); case TypeCode.Int64: return(valueConverter.ChangeType(_unionVal.i64Val, type)); case TypeCode.Double: return(valueConverter.ChangeType(_unionVal.dblVal, type)); case TypeCode.DateTime: return(valueConverter.ChangeType(_unionVal.dtVal, type)); default: Debug.Fail("Should never get here"); break; } } return(valueConverter.ChangeType(_objVal, type, nsResolver)); }
internal override Exception TryParseValue(object value, XmlNameTable nameTable, IXmlNamespaceResolver namespaceResolver, out object typedValue) { Exception exception; if (value == null) { throw new ArgumentNullException("value"); } string s = value as string; typedValue = null; if (s != null) { return(this.TryParseValue(s, nameTable, namespaceResolver, out typedValue)); } try { object obj2 = this.ValueConverter.ChangeType(value, this.ValueType, namespaceResolver); Array array = obj2 as Array; bool hasLexicalFacets = this.itemType.HasLexicalFacets; bool hasValueFacets = this.itemType.HasValueFacets; System.Xml.Schema.FacetsChecker facetsChecker = this.itemType.FacetsChecker; XmlValueConverter valueConverter = this.itemType.ValueConverter; for (int i = 0; i < array.Length; i++) { object obj3 = array.GetValue(i); if (hasLexicalFacets) { string parseString = (string)valueConverter.ChangeType(obj3, typeof(string), namespaceResolver); exception = facetsChecker.CheckLexicalFacets(ref parseString, this.itemType); if (exception != null) { return(exception); } } if (hasValueFacets) { exception = facetsChecker.CheckValueFacets(obj3, this.itemType); if (exception != null) { return(exception); } } } if (this.HasLexicalFacets) { string str3 = (string)this.ValueConverter.ChangeType(obj2, typeof(string), namespaceResolver); exception = DatatypeImplementation.listFacetsChecker.CheckLexicalFacets(ref str3, this); if (exception != null) { return(exception); } } if (this.HasValueFacets) { exception = DatatypeImplementation.listFacetsChecker.CheckValueFacets(obj2, this); if (exception != null) { return(exception); } } typedValue = obj2; return(null); } catch (FormatException exception2) { exception = exception2; } catch (InvalidCastException exception3) { exception = exception3; } catch (OverflowException exception4) { exception = exception4; } catch (ArgumentException exception5) { exception = exception5; } return(exception); }