protected void UpdateAvailableRules <TRule>() where TRule : IRule { if (AvailableRules == null) { AvailableRules = new ObservableCollection <IRule>(); } var rules = ImportRulesLocator.GetBehaviors().Where(r => r is TRule).ToArray(); if (AvailableRules.Count == 0) { foreach (var rule in rules) { AvailableRules.Add(rule); } return; } var toDelete = AvailableRules.Where(r => !rules.Contains(r)).ToArray(); var toAdd = rules.Where(r => !AvailableRules.Contains(r)).ToArray(); foreach (var rule in toDelete) { AvailableRules.Remove(rule); } foreach (var rule in toAdd) { AvailableRules.Add(rule); } }
public IRule Create(AvailableRules action) => _factories[action];