public static void AreEqual(XObject expected, XObject actual) { if (expected is XDocument) { expected = ((XDocument)expected).Root; } if (actual is XDocument) { actual = ((XDocument)actual).Root; } if (expected == null && actual == null) { return; } if (expected == null) { RaiseAssertFailure(null, actual); return; } if (actual == null) { RaiseAssertFailure(expected, null); return; } if (expected.GetType() != actual.GetType()) { RaiseAssertFailure(expected, actual); return; } AssertEqualValues(expected, actual); }
private IEnumerable<XPathPart> GetPathParts(XObject node) { XElement selectedElement; if(IsElement(node)) { selectedElement = (XElement)node; } else if(IsAttribute(node)) { selectedElement = node.Parent; } else { throw new ArgumentException("Node is not an element or attribute: " + node.GetType(), nameof(node)); } var parts = new List<XPathPart>(); var ancestorsAndSelf = selectedElement.AncestorsAndSelf().Reverse(); foreach(var ancestor in ancestorsAndSelf) { var part = new XPathPart(); part.Node = ancestor; part.Predicates = ancestor.Attributes().Where(MatchesAnyFilter).ToArray(); parts.Add(part); } if(IsAttribute(node)) { parts.Add(new XPathPart {Node = node}); } return parts; }
public static XObjectWrapper MakeWrapper(XObject obj) { if (obj is XAttribute) return MakeWrapper((XAttribute)obj); if (obj is XComment) return MakeWrapper((XComment)obj); if (obj is XProcessingInstruction) return MakeWrapper((XProcessingInstruction)obj); if (obj is XText) return MakeWrapper((XText)obj); if (obj is XElement) return MakeWrapper((XElement)obj); if (obj is XDocument) return MakeWrapper((XDocument)obj); throw new NotSupportedException(obj.GetType().FullName); }
public XObjectNotSupportedException(XObject @object) : base("Xml object '{0}' not supported. Only XElements and XAttributes are supported." .ToFormat(@object.GetType().Name)) { }
private static string GetXPathName(XObject xObject, IDictionary <string, string> namespacePrefixes) { return(XpathNames[xObject.GetType()].GetXpathName(xObject, namespacePrefixes)); }
public void AssertNodeIs <T> () { XObject n = Nodes.Peek(); Assert.IsTrue(n is T, "Node is {0}, not {1}", n.GetType().Name, typeof(T).Name); }
internal override void GatherLayouts() { if (xo is XObjectGen) { AddTypeLayout(xo.ObjectType); } else if (xo is XArrayGeneric) { return; } else { throw new Exception(string.Format("internal error: EmitInstanceEmbedded on {0}", xo.GetType())); } }
internal override void PrintContents( TextWriter tw, int indent, XObjectGen xog) { tw.WriteLine("{"); for (int i = 0; i < size; i++) { if (i != 0) { tw.WriteLine(","); } Compiler.Indent(tw, indent + 1); XObject xo = xog.embeds[off + i]; if (xo is XObjectGen) { CCValues.PrintObjectGen(tw, indent + 1, (XObjectGen)xo); } else if (xo is XArrayGeneric) { CCValues.PrintArray(tw, indent + 1, (XArrayGeneric)xo); } else { throw new Exception(string.Format("unsupported embedded type: {0}", xo.GetType())); } } tw.WriteLine(); Compiler.Indent(tw, indent); tw.Write("}"); }
public static IEnumerable <T> Select <T>(string xpath, IXmlNamespaceResolver resolver, object arg) where T : XObject { XPath2NodeIterator iter = XPath2NodeIterator.Create(Compile(xpath, resolver).EvaluateWithProperties(null, arg)); foreach (XPathItem item in iter) { if (item.IsNode) { XPathNavigator curr = (XPathNavigator)item; XObject o = (XObject)curr.UnderlyingObject; if (!(o is T)) { throw new InvalidOperationException(String.Format("Unexpected evalution {0}", o.GetType())); } yield return((T)o); } else { throw new InvalidOperationException(String.Format("Unexpected evalution {0}", item.TypedValue.GetType())); } } }
private IEnumerable <XPathPart> GetPathParts(XObject node) { XElement selectedElement; if (IsElement(node)) { selectedElement = (XElement)node; } else if (IsAttribute(node)) { selectedElement = node.Parent; } else { throw new ArgumentException("Node is not an element or attribute: " + node.GetType(), nameof(node)); } var parts = new List <XPathPart>(); var ancestorsAndSelf = selectedElement.AncestorsAndSelf().Reverse(); foreach (var ancestor in ancestorsAndSelf) { var part = new XPathPart(); part.Node = ancestor; part.Predicates = ancestor.Attributes().Where(MatchesAnyFilter).ToArray(); parts.Add(part); } if (IsAttribute(node)) { parts.Add(new XPathPart { Node = node }); } return(parts); }