internal DesktopTreeXPathNavigator(XPathItem item) { if (item == null) { throw new ArgumentNullException("item"); } this.item = item; }
internal DesktopTreeXPathNavigator(AutomationElement element) { if (element == null) { throw new ArgumentNullException("element"); } this.item = ElementItem.Create(element); }
private bool MoveToItem(XPathItem newItem) { if (newItem == null) { return false; } this.item = newItem; return true; }
private T ValueOrDefault <T>(XPathItem item) => item.Value == String.Empty ? default(T) : (T)item.ValueAs(typeof(T));
public static float ItemToFloat(XPathItem value) { return(XmlConvert.ToSingle(value.Value)); }
public static byte [] ItemToHexBinary(XPathItem value) { return(XmlConvert.FromBinHexString(value.Value)); }
public static TimeSpan ItemToDayTimeDuration(XPathItem value) { return(XmlConvert.ToTimeSpan(value.Value)); }
public static double ItemToDouble(XPathItem value) { return(XmlConvert.ToDouble(value.Value)); }
// See XQuery & XPath 2.0 functions & operators section 17. public static bool CanConvert(XPathItem item, XmlSchemaType schemaTypeDest) { if (item == null) { throw new ArgumentNullException("item"); } if (schemaTypeDest == null) { throw new ArgumentNullException("schemaTypeDest"); } XmlTypeCode src = item.XmlType.TypeCode; XmlTypeCode dst = schemaTypeDest.TypeCode; // Notation cannot be converted from other than Notation if (src == XmlTypeCode.Notation && dst != XmlTypeCode.Notation) { return(false); } // untypedAtomic and string are convertable unless source type is QName. switch (dst) { case XmlTypeCode.UntypedAtomic: case XmlTypeCode.String: return(src != XmlTypeCode.QName); } switch (src) { case XmlTypeCode.None: case XmlTypeCode.Item: case XmlTypeCode.Node: case XmlTypeCode.Document: case XmlTypeCode.Element: case XmlTypeCode.Attribute: case XmlTypeCode.Namespace: case XmlTypeCode.ProcessingInstruction: case XmlTypeCode.Comment: case XmlTypeCode.Text: throw new NotImplementedException(); // FIXME: check what happens case XmlTypeCode.AnyAtomicType: throw new NotImplementedException(); // FIXME: check what happens case XmlTypeCode.UntypedAtomic: case XmlTypeCode.String: // 'M' throw new NotImplementedException(); // FIXME: check what happens case XmlTypeCode.Boolean: case XmlTypeCode.Decimal: switch (dst) { case XmlTypeCode.Float: case XmlTypeCode.Double: case XmlTypeCode.Decimal: case XmlTypeCode.Boolean: return(true); } return(false); case XmlTypeCode.Float: case XmlTypeCode.Double: if (dst == XmlTypeCode.Decimal) { // 'M' throw new NotImplementedException(); // FIXME: check what happens } goto case XmlTypeCode.Decimal; case XmlTypeCode.Duration: switch (dst) { case XmlTypeCode.Duration: case XmlTypeCode.YearMonthDuration: case XmlTypeCode.DayTimeDuration: return(true); } return(false); case XmlTypeCode.DateTime: switch (dst) { case XmlTypeCode.DateTime: case XmlTypeCode.Time: case XmlTypeCode.Date: case XmlTypeCode.GYearMonth: case XmlTypeCode.GYear: case XmlTypeCode.GMonthDay: case XmlTypeCode.GDay: case XmlTypeCode.GMonth: return(true); } return(false); case XmlTypeCode.Time: switch (dst) { case XmlTypeCode.Time: case XmlTypeCode.Date: return(true); } return(false); case XmlTypeCode.Date: if (dst == XmlTypeCode.Time) { return(false); } goto case XmlTypeCode.DateTime; case XmlTypeCode.GYearMonth: case XmlTypeCode.GYear: case XmlTypeCode.GMonthDay: case XmlTypeCode.GDay: case XmlTypeCode.GMonth: return(src == dst); case XmlTypeCode.HexBinary: case XmlTypeCode.Base64Binary: if (src == dst) { return(true); } switch (dst) { case XmlTypeCode.HexBinary: case XmlTypeCode.Base64Binary: return(true); } return(false); case XmlTypeCode.AnyUri: case XmlTypeCode.QName: case XmlTypeCode.Notation: return(src == dst); case XmlTypeCode.NormalizedString: case XmlTypeCode.Token: case XmlTypeCode.Language: case XmlTypeCode.NmToken: case XmlTypeCode.Name: case XmlTypeCode.NCName: case XmlTypeCode.Id: case XmlTypeCode.Idref: case XmlTypeCode.Entity: case XmlTypeCode.Integer: case XmlTypeCode.NonPositiveInteger: case XmlTypeCode.NegativeInteger: case XmlTypeCode.Long: case XmlTypeCode.Int: case XmlTypeCode.Short: case XmlTypeCode.Byte: case XmlTypeCode.NonNegativeInteger: case XmlTypeCode.UnsignedLong: case XmlTypeCode.UnsignedInt: case XmlTypeCode.UnsignedShort: case XmlTypeCode.UnsignedByte: case XmlTypeCode.PositiveInteger: throw new NotImplementedException(); // xdt:* case XmlTypeCode.YearMonthDuration: if (dst == XmlTypeCode.DayTimeDuration) { return(false); } goto case XmlTypeCode.Duration; case XmlTypeCode.DayTimeDuration: if (dst == XmlTypeCode.YearMonthDuration) { return(false); } goto case XmlTypeCode.Duration; } throw new NotImplementedException(); }
public static byte [] ItemToBase64Binary(XPathItem value) { return(Convert.FromBase64String(value.Value)); }
public static XPathItem ItemToItem(XPathItem value, XmlSchemaType schemaTypeDest) { return(new XPathAtomicValue(value.Value, schemaTypeDest)); }
internal override bool IsSamePosition(XPathItem item) { var obj = item as ElementItem; return obj != null && obj._element.Equals(this._element); }
public static long ItemToInteger(XPathItem value) { return(XmlConvert.ToInt64(value.Value)); }
public static IList <XPathNavigator> ToNodeSet(XPathItem item) { return(new XmlQueryNodeSequence(ToNode(item))); }
public SingleIterator(XPathItem item) { _item = item; }
public void Serialize(IEnumerable <XPathItem> items, XmlWriter output) { items = items ?? Enumerable.Empty <XPathItem>(); IEnumerator <XPathItem> enumerator = items.GetEnumerator(); XPathItem lastItem = null; StringBuilder textBuffer = null; while (enumerator.MoveNext()) { XPathItem item = enumerator.Current; if (item == null) { continue; } if (item.IsNode) { XPathNavigator node = (XPathNavigator)item; switch (node.NodeType) { case XPathNodeType.SignificantWhitespace: case XPathNodeType.Text: case XPathNodeType.Whitespace: if (textBuffer == null) { textBuffer = new StringBuilder(); } textBuffer.Append(node.Value); break; default: if (textBuffer != null) { output.WriteString(textBuffer.ToString()); textBuffer = null; } node.WriteSubtree(output); break; } } else { if (textBuffer == null) { textBuffer = new StringBuilder(); } if (!lastItem.IsNode) { textBuffer.Append(" "); } textBuffer.Append(item.Value); } lastItem = item; } if (lastItem == null) { // Empty sequence, write empty string output.WriteString(""); } else if (textBuffer != null) { output.WriteString(textBuffer.ToString()); } }
public void Serialize(XPathItem item, XmlWriter output) { Serialize(new XPathItem[1] { item }, output); }
public void Serialize(XPathItem item, TextWriter output, XPathSerializationOptions options) { Serialize(new XPathItem[1] { item }, output, options); }
/// <summary> /// Write a top-level item by reference. /// </summary> public override void WriteItem(XPathItem item) { // Preserve identity _seqTyped.AddClone(item); }
public static string ItemToAnyUri(XPathItem value) { return(value.Value); }
/// <summary> /// Write a top-level item by reference. /// </summary> public abstract void WriteItem(XPathItem item);
public static bool ItemToBoolean(XPathItem value) { return(XmlConvert.ToBoolean(value.Value)); }
/// <summary> /// Convert from the Clr type of "value" to Clr type "destinationType" using V1 Xslt rules. /// These rules include converting any Rtf values to Nodes. /// </summary> internal object ChangeTypeXsltArgument(XmlQueryType xmlType, object value, Type destinationType) { #if FEATURE_COMPILED_XSL Debug.Assert(XmlILTypeHelper.GetStorageType(xmlType).IsAssignableFrom(value.GetType()), "Values passed to ChangeTypeXsltArgument should be in ILGen's default Clr representation."); #endif Debug.Assert(destinationType == XsltConvert.ObjectType || !destinationType.IsAssignableFrom(value.GetType()), "No need to call ChangeTypeXsltArgument since value is already assignable to destinationType " + destinationType); switch (xmlType.TypeCode) { case XmlTypeCode.String: if (destinationType == XsltConvert.DateTimeType) { value = XsltConvert.ToDateTime((string)value); } break; case XmlTypeCode.Double: if (destinationType != XsltConvert.DoubleType) { value = Convert.ChangeType(value, destinationType, CultureInfo.InvariantCulture); } break; case XmlTypeCode.Node: Debug.Assert(xmlType != XmlQueryTypeFactory.Node && xmlType != XmlQueryTypeFactory.NodeS, "Rtf values should have been eliminated by caller."); if (destinationType == XsltConvert.XPathNodeIteratorType) { value = new XPathArrayIterator((IList)value); } else if (destinationType == XsltConvert.XPathNavigatorArrayType) { // Copy sequence to XPathNavigator[] IList <XPathNavigator> seq = (IList <XPathNavigator>)value; XPathNavigator[] navArray = new XPathNavigator[seq.Count]; for (int i = 0; i < seq.Count; i++) { navArray[i] = seq[i]; } value = navArray; } break; case XmlTypeCode.Item: { // Only typeof(object) is supported as a destination type if (destinationType != XsltConvert.ObjectType) { throw new XslTransformException(SR.Xslt_UnsupportedClrType, destinationType.Name); } // Convert to default, backwards-compatible representation // 1. NodeSet: System.Xml.XPath.XPathNodeIterator // 2. Rtf: System.Xml.XPath.XPathNavigator // 3. Other: Default V1 representation IList <XPathItem> seq = (IList <XPathItem>)value; if (seq.Count == 1) { XPathItem item = seq[0]; if (item.IsNode) { // Node or Rtf RtfNavigator rtf = item as RtfNavigator; if (rtf != null) { value = rtf.ToNavigator(); } else { value = new XPathArrayIterator((IList)value); } } else { // Atomic value value = item.TypedValue; } } else { // Nodeset value = new XPathArrayIterator((IList)value); } break; } } Debug.Assert(destinationType.IsAssignableFrom(value.GetType()), "ChangeType from type " + value.GetType().Name + " to type " + destinationType.Name + " failed"); return(value); }
public static decimal ItemToDecimal(XPathItem value) { return(XmlConvert.ToDecimal(value.Value)); }
/// <summary> /// Return true if the type of "item" matches the xml type identified by "idxType". /// </summary> public bool MatchesXmlType(XPathItem item, int indexType) { return(CreateXmlType(item).IsSubtypeOf(GetXmlType(indexType))); }
public static string ItemToDuration(XPathItem value) { return(XmlConvert.ToString(XmlConvert.ToTimeSpan(value.Value))); }
public override object Invoke(XPathSequence current, object [] args) { MethodInfo mi = methods [args.Length] as MethodInfo; if (mi == null) { throw new ArgumentException("The number of custom function parameter does not match with the registered method's signature."); } ParameterInfo [] prms = mi.GetParameters(); // Use Evidence and PermissionSet.Demand() here // before invoking external function. Evidence e = current.Context.StaticContext.Evidence; if (e != null) { SecurityManager.ResolvePolicy(e).Demand(); } Type t = prms.Length > 0 ? prms [0].ParameterType : null; bool ctxSeq = mi.GetCustomAttributes( typeof(XQueryFunctionContextAttribute), false).Length > 0; if (t == typeof(XQueryContext)) { ArrayList pl = new ArrayList(args); pl.Insert(0, current.Context); args = pl.ToArray(); } else if (ctxSeq) { ArrayList pl = new ArrayList(args); pl.Insert(0, current); args = pl.ToArray(); } if (args.Length != prms.Length) { throw new XmlQueryException(String.Format("Argument numbers were different for function {0}. Signature requires {1} while actual call was {2}.", mi.Name, prms.Length, args.Length)); } // If native parameter type is XPathSequence and the actual values are not, adjust them for (int i = 0; i < args.Length; i++) { if (prms [i].ParameterType == typeof(XPathSequence) && !(args [i] is XPathSequence)) { XPathItem item = args [i] as XPathItem; if (item == null) { item = args [i] == null ? null : new XPathAtomicValue(args [i], InternalPool.GetBuiltInType(InternalPool.XmlTypeCodeFromRuntimeType(prms [i].ParameterType, true))); } if (item == null) { args [i] = new XPathEmptySequence(current.Context); } else { args [i] = new SingleItemIterator(item, current.Context); } } } return(mi.Invoke(null, args)); }
public static DateTime ItemToGYearMonth(XPathItem value) { return(XmlConvert.ToDateTime(value.Value)); }
public static decimal ItemToNonPositiveInteger(XPathItem value) { return(XmlConvert.ToDecimal(value.Value)); }
public override bool MoveTo(XPathNavigator other) { var obj = other as DesktopTreeXPathNavigator; if (obj == null) { return false; } this.item = obj.item; return true; }
public static XmlQualifiedName ItemToQName(XPathItem value) { return((XmlQualifiedName)value.TypedValue); }
public static long ItemToUnsignedInt(XPathItem value) { return(XmlConvert.ToInt32(value.Value)); }
public static decimal ItemToUnsignedLong(XPathItem value) { return(XmlConvert.ToInt32(value.Value)); }
internal override bool IsSamePosition(XPathItem item) { var obj = item as PropertyItem; return obj != null && obj.parent == this.parent && obj.property.Equals(this.property); }
public static int ItemToUnsignedShort(XPathItem value) { return(XmlConvert.ToInt32(value.Value)); }
internal abstract bool IsSamePosition(XPathItem item);
public void Serialize(XPathItem item, TextWriter output) { Serialize(item, output, null); }