using System.Collections.Generic; using System.Linq; using System.Reflection; namespace QFSW.QC { /// /// A set of rules for determining which entities should and shouldn't be scanned by Quantum Console for commands. /// public class QuantumScanRuleset { private readonly IQcScanRule[] _scanRules; /// /// Creates a Quantum Scan Ruleset with a custom set of scan rules. /// /// The IQcScanRules to use in this Quantum Scan Ruleset. public QuantumScanRuleset(IEnumerable scanRules) { _scanRules = scanRules.ToArray(); } /// /// Creates a Quantum Scan Ruleset with the default injected scan rules /// public QuantumScanRuleset() : this(new InjectionLoader().GetInjectedInstances()) { } /// /// Queries if the entity should be scanned. /// /// The entity to query. /// If the entity should be scanned. public bool ShouldScan(T entity) where T : ICustomAttributeProvider { bool shouldScan = true; foreach (IQcScanRule scanRule in _scanRules) { switch (scanRule.ShouldScan(entity)) { case ScanRuleResult.Accept: { break; } case ScanRuleResult.Reject: { shouldScan = false; break; } case ScanRuleResult.ForceAccept: { return true; } } } return shouldScan; } } }