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; /// /// Creates a new instance of the RulesetValidatorSelector. /// public MultiRuleSetValidatorSelector(params string[] rulesetsToExecute) { this.rulesetsToExecute = rulesetsToExecute; } /// /// Determines whether or not a rule should execute. /// /// The rule /// Property path (eg Customer.Address.Line1) /// Contextual information /// Whether or not the validator can execute. 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; } } }