forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiRuleSetValidatorSelector.cs
More file actions
36 lines (32 loc) · 1.41 KB
/
MultiRuleSetValidatorSelector.cs
File metadata and controls
36 lines (32 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceStack.FluentValidation.Internal;
using ServiceStack.FluentValidation;
namespace ServiceStack.ServiceInterface.Validation
{
public class MultiRuleSetValidatorSelector : IValidatorSelector
{
readonly string[] rulesetsToExecute;
/// <summary>
/// Creates a new instance of the RulesetValidatorSelector.
/// </summary>
public MultiRuleSetValidatorSelector(params string[] rulesetsToExecute) {
this.rulesetsToExecute = rulesetsToExecute;
}
/// <summary>
/// Determines whether or not a rule should execute.
/// </summary>
/// <param name="rule">The rule</param>
/// <param name="propertyPath">Property path (eg Customer.Address.Line1)</param>
/// <param name="context">Contextual information</param>
/// <returns>Whether or not the validator can execute.</returns>
public bool CanExecute(IValidationRule rule, string propertyPath, ValidationContext context) {
if (string.IsNullOrEmpty(rule.RuleSet)) return true;
if (!string.IsNullOrEmpty(rule.RuleSet) && rulesetsToExecute.Length > 0 && rulesetsToExecute.Contains(rule.RuleSet)) return true;
if (rulesetsToExecute.Contains("*")) return true;
return false;
}
}
}