Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Activities.Core.Presentation / System / Activities / Core / Presentation / SwitchTryCatchDesignerHelper.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Core.Presentation
5 {
6     using System.Activities.Presentation;
7     using System.Activities.Presentation.Model;
8     using System.Activities.Presentation.View;
9
10     static class SwitchTryCatchDesignerHelper
11     {
12         public static void MakeRootDesigner(WorkflowViewElement wve)
13         {
14             DesignerView designerView = wve.Context.Services.GetService<DesignerView>();
15             if (!wve.Equals(designerView.RootDesigner))
16             {
17                 designerView.MakeRootDesigner(wve.ModelItem);
18             }
19         }
20
21         public static void MakeParentRootDesigner<TParentType>(WorkflowViewElement wve)
22             where TParentType : WorkflowViewElement
23         {
24             WorkflowViewElement view = FindParentDesigner<TParentType>(wve);
25             if (view != null)
26             {
27                 MakeRootDesigner(view);
28             }
29         }
30
31         static TParentType FindParentDesigner<TParentType>(WorkflowViewElement wve) 
32             where TParentType : WorkflowViewElement
33         {
34             ModelItem parent = wve.ModelItem.Parent;
35             while (parent != null)
36             {
37                 if (parent.View != null && parent.View is TParentType)
38                 {
39                     return (TParentType)parent.View;
40                 }
41                 parent = parent.Parent;
42             }
43             return null;
44         }
45     }
46 }