示例#1
0
 private void MyEnumerate(ElementEnumerateEventHandler handler, ElementEnumerateEventArgs args)
 {
     foreach (DomElement element in this.Elements)
     {
         args._Parent     = this;
         args._Element    = element;
         args.CancelChild = false;
         handler(this, args);
         if (args.Cancel)
         {
             break;
         }
         if (args.CancelChild == false)
         {
             if (element is DomContainerElement)
             {
                 ((DomContainerElement)element).MyEnumerate(handler, args);
                 if (args.Cancel)
                 {
                     break;
                 }
             }
         }
         args.CancelChild = false;
     }
 }
示例#2
0
        /// <summary>
        /// 遍历子孙元素
        /// </summary>
        /// <param name="includeSelfNode">是否包含节点本身</param>
        /// <param name="handler">遍历过程的委托对象</param>
        public void Enumerate(ElementEnumerateEventHandler handler, bool includeSelfNode)
        {
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }
            ElementEnumerateEventArgs args = new ElementEnumerateEventArgs();

            if (includeSelfNode)
            {
                args._Parent  = this.Parent;
                args._Element = this;
                handler(this, args);
                if (args.Cancel || args.CancelChild)
                {
                    return;
                }
            }
            MyEnumerate(handler, args);
        }