예제 #1
0
        public override object ValueAs(Type type, IXmlNamespaceResolver nsResolver)
        {
            switch (XmlTypeCodeFromRuntimeType(type, false))
            {
            case XmlTypeCode.Int:
            case XmlTypeCode.Short:
            case XmlTypeCode.UnsignedShort:
                return(ValueAsInt);

            case XmlTypeCode.Double:
            case XmlTypeCode.Float:
                return(ValueAsDouble);

            case XmlTypeCode.Long:
            case XmlTypeCode.UnsignedInt:
                return(ValueAsLong);

            case XmlTypeCode.String:
                return(Value);

            case XmlTypeCode.DateTime:
                return(ValueAsDateTime);

            case XmlTypeCode.Boolean:
                return(ValueAsBoolean);

            case XmlTypeCode.Item:
                return(TypedValue);

            case XmlTypeCode.QName:
                return(XmlQualifiedName.Parse(Value, nsResolver));
            }
            throw new NotImplementedException();
        }
        internal override Exception TryParseValue(string s, XmlNameTable nameTable, IXmlNamespaceResolver nsmgr, out object typedValue)
        {
            typedValue = null;
            if ((s == null) || (s.Length == 0))
            {
                return(new XmlSchemaException("Sch_EmptyAttributeValue", string.Empty));
            }
            Exception exception = DatatypeImplementation.qnameFacetsChecker.CheckLexicalFacets(ref s, this);

            if (exception == null)
            {
                XmlQualifiedName name = null;
                try
                {
                    string str;
                    name = XmlQualifiedName.Parse(s, nsmgr, out str);
                }
                catch (ArgumentException exception2)
                {
                    return(exception2);
                }
                catch (XmlException exception3)
                {
                    return(exception3);
                }
                exception = DatatypeImplementation.qnameFacetsChecker.CheckValueFacets(name, this);
                if (exception == null)
                {
                    typedValue = name;
                    return(null);
                }
            }
            return(exception);
        }
예제 #3
0
        public override object ParseValue(string s, XmlNameTable nameTable, IXmlNamespaceResolver nsmgr)
        {
            object obj2;

            if ((s == null) || (s.Length == 0))
            {
                throw new XmlSchemaException("Sch_EmptyAttributeValue", string.Empty);
            }
            if (nsmgr == null)
            {
                throw new ArgumentNullException("nsmgr");
            }
            try
            {
                string str;
                obj2 = XmlQualifiedName.Parse(s.Trim(), nsmgr, out str);
            }
            catch (XmlSchemaException exception)
            {
                throw exception;
            }
            catch (Exception exception2)
            {
                throw new XmlSchemaException(Res.GetString("Sch_InvalidValue", new object[] { s }), exception2);
            }
            return(obj2);
        }
예제 #4
0
        public override object ParseValue(string s, XmlNameTable nameTable, IXmlNamespaceResolver nsmgr)
        {
            if (nameTable == null)
            {
                throw new ArgumentNullException("name table");
            }
            if (nsmgr == null)
            {
                throw new ArgumentNullException("namespace manager");
            }
            XmlQualifiedName xmlQualifiedName = XmlQualifiedName.Parse(s, nsmgr, true);

            nameTable.Add(xmlQualifiedName.Name);
            nameTable.Add(xmlQualifiedName.Namespace);
            return(xmlQualifiedName);
        }
예제 #5
0
        public /*override*/ object ValueAs(Type type, IXmlNamespaceResolver nsResolver)
        {
            switch (XmlTypeCodeFromRuntimeType(type, false))
            {
            case XmlTypeCode.Int:
            case XmlTypeCode.Short:
            case XmlTypeCode.UnsignedShort:
                return(ValueAsInt);

            case XmlTypeCode.Decimal:
                return(ValueAsDecimal);

            case XmlTypeCode.Double:
            case XmlTypeCode.Float:
                return(ValueAsDouble);

            case XmlTypeCode.Long:
            case XmlTypeCode.UnsignedInt:
                return(ValueAsLong);

            case XmlTypeCode.String:
                return(Value);

            case XmlTypeCode.DateTime:
                return(ValueAsDateTime);

            case XmlTypeCode.Boolean:
                return(ValueAsBoolean);

            case XmlTypeCode.Item:
                return(TypedValue);

            case XmlTypeCode.QName:
                return(XmlQualifiedName.Parse(Value, nsResolver, true));

            case XmlTypeCode.Base64Binary:
            case XmlTypeCode.HexBinary:
                if (bytesValue != null)
                {
                    return(bytesValue);
                }
                break;
            }
            throw new NotImplementedException();
        }
예제 #6
0
        /// <summary>Returns the validated XML element or attribute's value as the type specified using the <see cref="T:System.Xml.IXmlNamespaceResolver" /> object specified to resolve namespace prefixes.</summary>
        /// <returns>The value of the validated XML element or attribute as the type requested.</returns>
        /// <param name="type">The type to return the validated XML element or attribute's value as.</param>
        /// <param name="nsResolver">The <see cref="T:System.Xml.IXmlNamespaceResolver" /> object used to resolve namespace prefixes.</param>
        /// <exception cref="T:System.FormatException">The validated XML element or attribute's value is not in the correct format for the target type.</exception>
        /// <exception cref="T:System.InvalidCastException">The attempted cast is not valid.</exception>
        /// <exception cref="T:System.OverflowException">The attempted cast resulted in an overflow.</exception>
        public override object ValueAs(Type type, IXmlNamespaceResolver nsResolver)
        {
            XmlTypeCode xmlTypeCode = XmlAtomicValue.XmlTypeCodeFromRuntimeType(type, false);

            switch (xmlTypeCode)
            {
            case XmlTypeCode.Long:
            case XmlTypeCode.UnsignedInt:
                return(this.ValueAsLong);

            case XmlTypeCode.Int:
            case XmlTypeCode.Short:
            case XmlTypeCode.UnsignedShort:
                return(this.ValueAsInt);

            default:
                switch (xmlTypeCode)
                {
                case XmlTypeCode.String:
                    return(this.Value);

                case XmlTypeCode.Boolean:
                    return(this.ValueAsBoolean);

                default:
                    if (xmlTypeCode == XmlTypeCode.Item)
                    {
                        return(this.TypedValue);
                    }
                    if (xmlTypeCode != XmlTypeCode.QName)
                    {
                        throw new NotImplementedException();
                    }
                    return(XmlQualifiedName.Parse(this.Value, nsResolver, true));

                case XmlTypeCode.Float:
                case XmlTypeCode.Double:
                    return(this.ValueAsDouble);

                case XmlTypeCode.DateTime:
                    return(this.ValueAsDateTime);
                }
                break;
            }
        }