c4b981dc7651ceaf67ab395a8875cd2590a6d75b
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / DesignTimeValidationFeature.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.Activities.Presentation
6 {
7     using System.Runtime;
8     using System.Globalization;
9     using System.Activities.Presentation.Validation;
10     using System.Activities.Validation;
11     using System.Collections.Generic;
12
13     abstract class DesignTimeValidationFeature : Feature
14     {
15         public override void Initialize(EditingContext context, Type modelType)
16         {
17             if (modelType != this.ApplyTo)
18             {
19                 throw FxTrace.Exception.AsError(new InvalidOperationException (
20                     string.Format(CultureInfo.CurrentCulture, SR.DesignTimeValidationFeatureOnlyAppliesToType, this.GetType(), this.ApplyTo, modelType)));
21             }
22
23             ValidationService validationService = context.Services.GetService<ValidationService>();
24             if (validationService != null)
25             {
26                 validationService.Settings.AdditionalConstraints.Add(this.ApplyTo, this.DesignTimeConstraints);
27             }
28         }
29
30         protected abstract Type ApplyTo
31         {
32             get;
33         }
34
35         protected abstract IList<Constraint> DesignTimeConstraints
36         {
37             get;
38         }
39     }
40 }