Example #1
0
        static XmlAtomicValue CreateInstance(XmlSchemaType xmlType)
        {
            XmlAtomicValue instance = (XmlAtomicValue)FormatterServices.GetUninitializedObject(atomicValueType);

            xmlTypeField.SetValue(instance, xmlType);

            return(instance);
        }
Example #2
0
        /// <summary>
        /// Extends ValueAs so that methods that return a specific type object given a Type parameter can be
        /// used as generic method and casting is not required.
        /// <example>
        /// xmlatomicvalue.ValueAs&lt;int&gt;(nsResolver);
        /// </example>
        /// </summary>
        public static T ValueAs <T>(this XmlAtomicValue xmlatomicvalue, System.Xml.IXmlNamespaceResolver nsResolver)
        {
            if (xmlatomicvalue == null)
            {
                throw new ArgumentNullException("xmlatomicvalue");
            }

            return((T)xmlatomicvalue.ValueAs(typeof(T), nsResolver));
        }
Example #3
0
        public override XPathItem CreateAtomicValue(object value, XmlQualifiedName qualifiedName)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            XmlAtomicValue instance = CreateInstance(qualifiedName);

            objValField.SetValue(instance, value);

            return(instance);
        }
Example #4
0
        public static XPathItem CreateString(String value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            XmlAtomicValue instance = CreateInstance(XmlTypeCode.String);

            objValField.SetValue(instance, value);

            return(instance);
        }
Example #5
0
        public static XPathItem CreateInt(Int32 value)
        {
            TypeCode clrType = TypeCode.Int32;

            XmlAtomicValue instance = CreateInstance(XmlTypeCode.Int);

            clrTypeField.SetValue(instance, clrType);

            object unionVal = unionValField.GetValue(instance);

            i32ValField.SetValue(unionVal, value);
            unionValField.SetValue(instance, unionVal);

            return(instance);
        }
Example #6
0
        public static XPathItem CreateDouble(Double value)
        {
            TypeCode clrType = TypeCode.Double;

            XmlAtomicValue instance = CreateInstance(XmlTypeCode.Double);

            clrTypeField.SetValue(instance, clrType);

            object unionVal = unionValField.GetValue(instance);

            dblValField.SetValue(unionVal, value);
            unionValField.SetValue(instance, unionVal);

            return(instance);
        }
Example #7
0
        public static XPathItem CreateBoolean(Boolean value)
        {
            TypeCode clrType = TypeCode.Boolean;

            XmlAtomicValue instance = CreateInstance(XmlTypeCode.Boolean);

            clrTypeField.SetValue(instance, clrType);

            object unionVal = unionValField.GetValue(instance);

            boolValField.SetValue(unionVal, value);
            unionValField.SetValue(instance, unionVal);

            return(instance);
        }
Example #8
0
        //------------------------------------------------------------------------
        // External type to external type
        //------------------------------------------------------------------------

        internal static XmlAtomicValue ConvertToType(XmlAtomicValue value, XmlQueryType destinationType)
        {
            Debug.Assert(destinationType.IsStrict && destinationType.IsAtomicValue, "Can only convert to strict atomic type.");

            // This conversion matrix should match the one in XmlILVisitor.GetXsltConvertMethod
            switch (destinationType.TypeCode)
            {
            case XmlTypeCode.Boolean:
                switch (value.XmlType.TypeCode)
                {
                case XmlTypeCode.Boolean:
                case XmlTypeCode.Double:
                case XmlTypeCode.String:
                    return(new XmlAtomicValue(destinationType.SchemaType, ToBoolean(value)));
                }
                break;

            case XmlTypeCode.DateTime:
                if (value.XmlType.TypeCode == XmlTypeCode.String)
                {
                    return(new XmlAtomicValue(destinationType.SchemaType, ToDateTime(value.Value)));
                }
                break;

            case XmlTypeCode.Decimal:
                if (value.XmlType.TypeCode == XmlTypeCode.Double)
                {
                    return(new XmlAtomicValue(destinationType.SchemaType, ToDecimal(value.ValueAsDouble)));
                }
                break;

            case XmlTypeCode.Double:
                switch (value.XmlType.TypeCode)
                {
                case XmlTypeCode.Boolean:
                case XmlTypeCode.Double:
                case XmlTypeCode.String:
                    return(new XmlAtomicValue(destinationType.SchemaType, ToDouble(value)));

                case XmlTypeCode.Decimal:
                    return(new XmlAtomicValue(destinationType.SchemaType, ToDouble((decimal)value.ValueAs(DecimalType, null))));

                case XmlTypeCode.Int:
                case XmlTypeCode.Long:
                    return(new XmlAtomicValue(destinationType.SchemaType, ToDouble(value.ValueAsLong)));
                }
                break;

            case XmlTypeCode.Int:
            case XmlTypeCode.Long:
                if (value.XmlType.TypeCode == XmlTypeCode.Double)
                {
                    return(new XmlAtomicValue(destinationType.SchemaType, ToLong(value.ValueAsDouble)));
                }
                break;

            case XmlTypeCode.String:
                switch (value.XmlType.TypeCode)
                {
                case XmlTypeCode.Boolean:
                case XmlTypeCode.Double:
                case XmlTypeCode.String:
                    return(new XmlAtomicValue(destinationType.SchemaType, ToString(value)));

                case XmlTypeCode.DateTime:
                    return(new XmlAtomicValue(destinationType.SchemaType, ToString(value.ValueAsDateTime)));
                }
                break;
            }

            Debug.Fail($"Conversion from {value.XmlType.QualifiedName.Name} to {destinationType} is not supported.");
            return(value);
        }
Example #9
0
 /// <summary>
 /// Cache all or part of the attribute's typed value.
 /// </summary>
 public void Init(XmlAtomicValue value)
 {
     this.text  = null;
     this.value = value;
 }
Example #10
0
 /// <summary>
 /// Cache all or part of the attribute's string value.
 /// </summary>
 public void Init(string text)
 {
     this.text  = text;
     this.value = null;
 }
Example #11
0
 /// <summary>
 /// Cache all or part of the attribute's typed value.
 /// </summary>
 public void Init(XmlAtomicValue value)
 {
     _text  = null;
     _value = value;
 }
Example #12
0
 /// <summary>
 /// Cache all or part of the attribute's string value.
 /// </summary>
 public void Init(string text)
 {
     _text  = text;
     _value = null;
 }