private void Reset() { foreach (var rule in Rules) { rule.SetSuccessor(null); } DisabledRules.Clear(); FailedRules.Clear(); PassedRules.Clear(); }
public void Load(Assembly assembly) { var types = assembly.GetTypes(); foreach (var type in types) { if (!type.IsSubclassOf(typeof(Rule))) { continue; } var friendlyNameAttribute = (FriendlyNameAttribute)Attribute.GetCustomAttribute(type, typeof(FriendlyNameAttribute)); var name = friendlyNameAttribute != null ? friendlyNameAttribute.Name : type.Name; var disableAttribute = (DisabledAttribute)Attribute.GetCustomAttribute(type, typeof(DisabledAttribute)); var group = string.Empty; var groupAttribute = (GroupAttribute)Attribute.GetCustomAttribute(type, typeof(GroupAttribute)); if (groupAttribute != null) { group = groupAttribute.Name; } var priority = uint.MaxValue; var priorityAttribute = (PriorityAttribute)Attribute.GetCustomAttribute(type, typeof(PriorityAttribute)); if (priorityAttribute != null) { priority = priorityAttribute.Priority; } IList <object> parameters = new List <object>(); if (ServiceProvider != null) { parameters = ResolveDependencies(type); } var rule = (Rule)Activator.CreateInstance(type, parameters.ToArray()); rule.Priority = priority; rule.Name = name; rule.Group = group; if (disableAttribute != null) { DisabledRules.Add(rule); continue; } Rules.Add(rule); } if (Rules.Any() == false) { throw new ArgumentException( "A referenced assembly must contain at least one subclass implementation of the abstract class Rule."); } }