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


C# Node.GetAncestor方法代码示例

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


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

示例1: VerifyParameterNodes

        //ExEnd
        //ExStart
        //ExId:ExtractBetweenNodes_Helpers
        //ExSummary:The helper methods used by the ExtractContent method.
        /// <summary>
        /// Checks the input parameters are correct and can be used. Throws an exception if there is any problem.
        /// </summary>
        private static void VerifyParameterNodes(Node startNode, Node endNode)
        {
            // The order in which these checks are done is important.
            if (startNode == null)
                throw new ArgumentException("Start node cannot be null");
            if (endNode == null)
                throw new ArgumentException("End node cannot be null");

            if (!startNode.Document.Equals(endNode.Document))
                throw new ArgumentException("Start node and end node must belong to the same document");

            if (startNode.GetAncestor(NodeType.Body) == null || endNode.GetAncestor(NodeType.Body) == null)
                throw new ArgumentException("Start node and end node must be a child or descendant of a body");

            // Check the end node is after the start node in the DOM tree
            // First check if they are in different sections, then if they're not check their position in the body of the same section they are in.
            Section startSection = (Section)startNode.GetAncestor(NodeType.Section);
            Section endSection = (Section)endNode.GetAncestor(NodeType.Section);

            int startIndex = startSection.ParentNode.IndexOf(startSection);
            int endIndex = endSection.ParentNode.IndexOf(endSection);

            if (startIndex == endIndex)
            {
                if (startSection.Body.IndexOf(startNode) > endSection.Body.IndexOf(endNode))
                    throw new ArgumentException("The end node must be after the start node in the body");
            }
            else if (startIndex > endIndex)
                throw new ArgumentException("The section of end node must be after the section start node");
        }
开发者ID:nancyeiceblue,项目名称:Aspose_Words_NET,代码行数:37,代码来源:Program.cs

示例2: IsInline

 /// <summary>
 /// Checks if a node passed is an inline node.
 /// </summary>
 private static bool IsInline(Node node)
 {
     // Test if the node is desendant of a Paragraph or Table node and also is not a paragraph or a table a paragraph inside a comment class which is decesant of a pararaph is possible.
     return ((node.GetAncestor(NodeType.Paragraph) != null || node.GetAncestor(NodeType.Table) != null) && !(node.NodeType == NodeType.Paragraph || node.NodeType == NodeType.Table));
 }
开发者ID:nancyeiceblue,项目名称:Aspose_Words_NET,代码行数:8,代码来源:Program.cs


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