public StrategyValidator(IValidationStrategy strategy) { if (strategy is null) { throw new ArgumentNullException(nameof(strategy)); } Handler = ValidationHandler.CreateByStrategy(strategy); Name = $"Strategy Validator for '{strategy.GetType().GetFriendlyName()}'"; }
public void RegisterStrategy <T>(IValidationStrategy strategy) { if (strategy == null) { throw new ArgumentException(); } Type type = typeof(T); if (Strategies.ContainsKey(type)) { if (Strategies[type].Any(str => str.GetType() == strategy.GetType())) { throw new DuplicateStrategyException(); } } else { Strategies.Add(type, new List <IValidationStrategy>()); } Strategies[type].Add(strategy); }