static XmlAtomicValue CreateInstance(XmlSchemaType xmlType) { XmlAtomicValue instance = (XmlAtomicValue)FormatterServices.GetUninitializedObject(atomicValueType); xmlTypeField.SetValue(instance, xmlType); return(instance); }
/// <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<int>(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)); }
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); }
public static XPathItem CreateString(String value) { if (value == null) { throw new ArgumentNullException("value"); } XmlAtomicValue instance = CreateInstance(XmlTypeCode.String); objValField.SetValue(instance, value); return(instance); }
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); }
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); }
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); }
//------------------------------------------------------------------------ // 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); }
/// <summary> /// Cache all or part of the attribute's typed value. /// </summary> public void Init(XmlAtomicValue value) { this.text = null; this.value = value; }
/// <summary> /// Cache all or part of the attribute's string value. /// </summary> public void Init(string text) { this.text = text; this.value = null; }
/// <summary> /// Cache all or part of the attribute's typed value. /// </summary> public void Init(XmlAtomicValue value) { _text = null; _value = value; }
/// <summary> /// Cache all or part of the attribute's string value. /// </summary> public void Init(string text) { _text = text; _value = null; }