当前位置: 首页>>代码示例>>C#>>正文


C# XNode.AddBeforeSelf方法代码示例

本文整理汇总了C#中System.Xml.Linq.XNode.AddBeforeSelf方法的典型用法代码示例。如果您正苦于以下问题:C# XNode.AddBeforeSelf方法的具体用法?C# XNode.AddBeforeSelf怎么用?C# XNode.AddBeforeSelf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XNode的用法示例。


在下文中一共展示了XNode.AddBeforeSelf方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteXDocumentVariation

 public void ExecuteXDocumentVariation(XNode[] toAdd, XNode contextNode)
 {
     IEnumerable<XNode> toAddList = toAdd.OfType<XNode>();
     XDocument xDoc = new XDocument(contextNode);
     XDocument xDocOriginal = new XDocument(xDoc);
     using (UndoManager undo = new UndoManager(xDoc))
     {
         undo.Group();
         using (EventsHelper docHelper = new EventsHelper(xDoc))
         {
             using (EventsHelper nodeHelper = new EventsHelper(contextNode))
             {
                 contextNode.AddBeforeSelf(toAdd);
                 Assert.True(toAddList.SequenceEqual(contextNode.NodesBeforeSelf(), XNode.EqualityComparer), "Nodes not added correctly!");
                 nodeHelper.Verify(0);
             }
             docHelper.Verify(XObjectChange.Add, toAdd);
         }
         undo.Undo();
         Assert.True(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:22,代码来源:EventsAdd.cs

示例2: ExecuteXElementVariation

 public void ExecuteXElementVariation(XNode[] toAdd, XNode contextNode)
 {
     IEnumerable<XNode> toAddList = toAdd.OfType<XNode>();
     XElement xElem = new XElement("root", contextNode);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper elemHelper = new EventsHelper(xElem))
         {
             using (EventsHelper nodeHelper = new EventsHelper(contextNode))
             {
                 contextNode.AddBeforeSelf(toAdd);
                 Assert.True(toAddList.SequenceEqual(contextNode.NodesBeforeSelf(), XNode.EqualityComparer), "Nodes not added correctly!");
                 nodeHelper.Verify(0);
             }
             elemHelper.Verify(XObjectChange.Add, toAdd);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:23,代码来源:EventsAdd.cs

示例3: EnsureFirstNodeWhitespaceSeparation

        /// <summary>
        ///     Ensures the whitespace separation for the first child element added to a node.
        /// </summary>
        /// <param name="element"></param>
        private void EnsureFirstNodeWhitespaceSeparation(XNode element)
        {
#if DEBUG
            if (element.Parent != null)
            {
                Debug.Assert(element.Parent.Elements().Count() == 1, "Unexpected count of elements!");
            }
            else
            {
                // if first.Parent is null, then this is the root element in a document
                Debug.Assert(element.Document.Root == element, "element had null parent, but is not the root element of the document");
            }
#endif

            var precedingNewLine = new XText(Environment.NewLine + new string(' ', GetIndentLevel() * 2));
            var trailingNewLine = new XText(Environment.NewLine + new string(' ', Parent.GetIndentLevel() * 2));
            element.AddBeforeSelf(precedingNewLine);
            element.AddAfterSelf(trailingNewLine);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:23,代码来源:EFElement.cs

示例4: EnsureWhitespaceBeforeNode

        /// <summary>
        ///     Ensures the whitespace separation between two nodes.  Appropriate whitespace is added before the given node
        /// </summary>
        /// <param name="first"></param>
        private XText EnsureWhitespaceBeforeNode(XNode node)
        {
            Debug.Assert(
                node.Parent != null && node.Parent.Elements().Count() > 0,
                "Call EnsureFirstNodeWhitespaceSeparation when the added element is the first node");

            var newLine = new XText(Environment.NewLine + new string(' ', GetIndentLevel() * 2));
            node.AddBeforeSelf(newLine);
            return newLine;
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:14,代码来源:EFElement.cs


注:本文中的System.Xml.Linq.XNode.AddBeforeSelf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。