예제 #1
0
 private static void BranchVisitor(LocationReportBuilder locationReportBuilder, BranchAccessor branchAccessor)
 {
     if (Equals(branchAccessor.FirstDockControl, locationReportBuilder.TargetDockControl))
     {
         locationReportBuilder.MarkFound(branchAccessor.Branch, false);
     }
     else if (Equals(branchAccessor.SecondDockControl, locationReportBuilder.TargetDockControl))
     {
         locationReportBuilder.MarkFound(branchAccessor.Branch, true);
     }
     else
     {
         branchAccessor.Visit(BranchItem.First, ba => BranchVisitor(locationReportBuilder, ba));
         if (locationReportBuilder.IsFound)
         {
             return;
         }
         branchAccessor.Visit(BranchItem.Second, ba => BranchVisitor(locationReportBuilder, ba));
     }
 }
예제 #2
0
        /// <summary>
        /// Helper method for <see cref="BranchAccessor.Visit"/> which allows a context to be passed through.
        /// </summary>
        /// <typeparam name="TContext"></typeparam>
        /// <param name="branchAccessor"></param>
        /// <param name="context"></param>
        /// <param name="childItem"></param>
        /// <param name="branchVisitor"></param>
        /// <param name="dockControlVisitor"></param>
        /// <param name="contentVisitor"></param>
        /// <returns></returns>
        public static BranchAccessor Visit <TContext>(
            this BranchAccessor branchAccessor,
            TContext context,
            BranchItem childItem,
            Action <TContext, BranchAccessor> branchVisitor   = null,
            Action <TContext, DockControl> dockControlVisitor = null,
            Action <TContext, object> contentVisitor          = null)
        {
            if (branchAccessor == null)
            {
                throw new ArgumentNullException(nameof(branchAccessor));
            }

            branchAccessor.Visit(
                childItem,
                WrapVisitor(context, branchVisitor),
                WrapVisitor(context, dockControlVisitor),
                WrapVisitor(context, contentVisitor)
                );

            return(branchAccessor);
        }