Merge pull request #2780 from alexanderkyte/seq_point_optimize
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Validation / ValidationRoot.cs
1 // <copyright>
2 //   Copyright (c) Microsoft Corporation.  All rights reserved.
3 // </copyright>
4
5 namespace System.Activities.Presentation.Validation
6 {
7     using System.Activities.Validation;
8     using System.Runtime;
9     using System.ServiceModel.Activities;
10
11     internal sealed class ValidationRoot
12     {
13         private WorkflowService workflowService;
14         private Activity activity;
15
16         public ValidationRoot(WorkflowService workflowService)
17         {
18             Fx.Assert(workflowService != null, "workflowService != null");
19             this.workflowService = workflowService;
20         }
21
22         public ValidationRoot(Activity activity)
23         {
24             Fx.Assert(activity != null, "activity!=null");
25             this.activity = activity;
26         }
27
28         public ValidationResults Validate(ValidationSettings settings)
29         {
30             if (this.workflowService != null)
31             {
32                 return this.workflowService.Validate(settings);
33             }
34             else
35             {
36                 return ActivityValidationServices.Validate(this.activity, settings);
37             }
38         }
39
40         public Activity Resolve(string id)
41         {
42             Fx.Assert(id != null, "id should not be null.");
43
44             Activity activityRoot = null;
45             if (this.workflowService != null)
46             {
47                 activityRoot = this.workflowService.GetWorkflowRoot();
48             }
49             else
50             {
51                 activityRoot = this.activity;
52             }
53
54             return ActivityValidationServices.Resolve(activityRoot, id);
55         }
56     }
57 }