コード例 #1
0
ファイル: XAssert.cs プロジェクト: bitserf/xmapper
        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);
        }
コード例 #2
0
        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;
        }
コード例 #3
0
ファイル: XObjectWrapper.cs プロジェクト: zanyants/saxon-xdoc
        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);
        }
コード例 #4
0
ファイル: XmlNodeBase.cs プロジェクト: mikeobrien/Bender
 public XObjectNotSupportedException(XObject @object)
     : base("Xml object '{0}' not supported. Only XElements and XAttributes are supported."
         .ToFormat(@object.GetType().Name))
 {
 }
コード例 #5
0
 private static string GetXPathName(XObject xObject, IDictionary <string, string> namespacePrefixes)
 {
     return(XpathNames[xObject.GetType()].GetXpathName(xObject, namespacePrefixes));
 }
コード例 #6
0
        public void AssertNodeIs <T> ()
        {
            XObject n = Nodes.Peek();

            Assert.IsTrue(n is T, "Node is {0}, not {1}", n.GetType().Name, typeof(T).Name);
        }
コード例 #7
0
 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()));
     }
 }
コード例 #8
0
 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("}");
 }
コード例 #9
0
ファイル: XPath2Expression.cs プロジェクト: semyonc/xpath2
        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()));
                }
            }
        }
コード例 #10
0
ファイル: XPathWriter.cs プロジェクト: ra2003/XPathTools
        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);
        }