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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        internal override Exception CheckValueFacets(double value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction    = datatype.Restriction;
            RestrictionFlags  flags          = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);
            XmlValueConverter valueConverter = datatype.ValueConverter;

            if (((flags & RestrictionFlags.MaxInclusive) != 0) && (value > valueConverter.ToDouble(restriction.MaxInclusive)))
            {
                return(new XmlSchemaException("Sch_MaxInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MaxExclusive) != 0) && (value >= valueConverter.ToDouble(restriction.MaxExclusive)))
            {
                return(new XmlSchemaException("Sch_MaxExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinInclusive) != 0) && (value < valueConverter.ToDouble(restriction.MinInclusive)))
            {
                return(new XmlSchemaException("Sch_MinInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinExclusive) != 0) && (value <= valueConverter.ToDouble(restriction.MinExclusive)))
            {
                return(new XmlSchemaException("Sch_MinExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, valueConverter))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(null);
        }
 private bool MatchEnumeration(double value, ArrayList enumeration, XmlValueConverter valueConverter)
 {
     for (int i = 0; i < enumeration.Count; i++)
     {
         if (value == valueConverter.ToDouble(enumeration[i]))
         {
             return true;
         }
     }
     return false;
 }
 internal bool MatchEnumeration(decimal value, ArrayList enumeration, XmlValueConverter valueConverter)
 {
     for (int i = 0; i < enumeration.Count; i++)
     {
         if (value == valueConverter.ToDecimal(enumeration[i]))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 6
0
 private bool MatchEnumeration(double value, ArrayList enumeration, XmlValueConverter valueConverter)
 {
     for (int i = 0; i < enumeration.Count; i++)
     {
         if (value == valueConverter.ToDouble(enumeration[i]))
         {
             return(true);
         }
     }
     return(false);
 }
 public static XmlValueConverter Create(XmlValueConverter atomicConverter)
 {
     if (atomicConverter == XmlUntypedConverter.Untyped)
     {
         return(XmlUntypedConverter.UntypedList);
     }
     if (atomicConverter == XmlAnyConverter.Item)
     {
         return(XmlAnyListConverter.ItemList);
     }
     if (atomicConverter == XmlAnyConverter.AnyAtomic)
     {
         return(XmlAnyListConverter.AnyAtomicList);
     }
     return(new XmlListConverter((XmlBaseConverter)atomicConverter));
 }
        internal override Exception CheckValueFacets(decimal value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction    = datatype.Restriction;
            RestrictionFlags  flags          = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);
            XmlValueConverter valueConverter = datatype.ValueConverter;

            if ((value > this.maxValue) || (value < this.minValue))
            {
                return(new OverflowException(Res.GetString("XmlConvert_Overflow", new object[] { value.ToString(CultureInfo.InvariantCulture), datatype.TypeCodeString })));
            }
            if (flags == 0)
            {
                return(null);
            }
            if (((flags & RestrictionFlags.MaxInclusive) != 0) && (value > valueConverter.ToDecimal(restriction.MaxInclusive)))
            {
                return(new XmlSchemaException("Sch_MaxInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MaxExclusive) != 0) && (value >= valueConverter.ToDecimal(restriction.MaxExclusive)))
            {
                return(new XmlSchemaException("Sch_MaxExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinInclusive) != 0) && (value < valueConverter.ToDecimal(restriction.MinInclusive)))
            {
                return(new XmlSchemaException("Sch_MinInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinExclusive) != 0) && (value <= valueConverter.ToDecimal(restriction.MinExclusive)))
            {
                return(new XmlSchemaException("Sch_MinExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, valueConverter))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(this.CheckTotalAndFractionDigits(value, restriction.TotalDigits, restriction.FractionDigits, (flags & RestrictionFlags.TotalDigits) != 0, (flags & RestrictionFlags.FractionDigits) != 0));
        }
Ejemplo n.º 9
0
 internal bool MatchEnumeration(decimal value, ArrayList enumeration, XmlValueConverter valueConverter) {
     for (int i = 0; i < enumeration.Count; ++i) {
         if (value == valueConverter.ToDecimal(enumeration[i])) {
             return true;
         }
     }
     return false;
 }
        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);
        }
 protected XmlListConverter(XmlBaseConverter atomicConverter, Type clrTypeDefault) : base(atomicConverter, clrTypeDefault)
 {
     this.atomicConverter = atomicConverter;
 }
 protected XmlListConverter(XmlBaseConverter atomicConverter) : base(atomicConverter)
 {
     this.atomicConverter = atomicConverter;
 }
Ejemplo n.º 13
0
 private bool MatchEnumeration(double value, ArrayList enumeration, XmlValueConverter valueConverter) {
     foreach(object correctValue in enumeration) {
         if (value == valueConverter.ToDouble(correctValue)) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 14
0
 internal bool MatchEnumeration(decimal value, ArrayList enumeration, XmlValueConverter valueConverter) {
     foreach(object correctValue in enumeration) {
         if (value == valueConverter.ToDecimal(correctValue)) {
             return true;
         }
     }
     return false;
 }