public BranchAccessor(Branch branch) { if (branch == null) { throw new ArgumentNullException("branch"); } _branch = branch; var firstChildBranch = branch.FirstItem as Branch; if (firstChildBranch != null) { _firstItemBranchAccessor = new BranchAccessor(firstChildBranch); } else { _firstItemTabablzControl = FindTabablzControl(branch.FirstItem, branch.FirstContentPresenter); } var secondChildBranch = branch.SecondItem as Branch; if (secondChildBranch != null) { _secondItemBranchAccessor = new BranchAccessor(secondChildBranch); } else { _secondItemTabablzControl = FindTabablzControl(branch.SecondItem, branch.SecondContentPresenter); } }
public LayoutAccessor(Layout layout) { if (layout == null) { throw new ArgumentNullException("layout"); } _layout = layout; var branch = Layout.Content as Branch; if (branch != null) { _branchAccessor = new BranchAccessor(branch); } else { _tabablzControl = Layout.Content as TabablzControl; } }
/// <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="tabablzControlVisitor"></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, TabablzControl> tabablzControlVisitor = null, Action <TContext, object> contentVisitor = null) { if (branchAccessor == null) { throw new ArgumentNullException("branchAccessor"); } branchAccessor.Visit( childItem, WrapVisitor(context, branchVisitor), WrapVisitor(context, tabablzControlVisitor), WrapVisitor(context, contentVisitor) ); return(branchAccessor); }
private static void BranchAccessorVisitor(IList <TabablzControl> resultSet, BranchAccessor branchAccessor) { branchAccessor .Visit(resultSet, BranchItem.First, BranchAccessorVisitor, TabablzControlVisitor) .Visit(resultSet, BranchItem.Second, BranchAccessorVisitor, TabablzControlVisitor); }
private static void BranchVisitor(LocationReportBuilder locationReportBuilder, BranchAccessor branchAccessor) { if (Equals(branchAccessor.FirstItemTabablzControl, locationReportBuilder.TargetTabablzControl)) { locationReportBuilder.MarkFound(branchAccessor.Branch, false); } else if (Equals(branchAccessor.SecondItemTabablzControl, locationReportBuilder.TargetTabablzControl)) { 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)); } }