public BaselineContextScope(ScopeType type, string moduleName, IBaselineSpec option) { Type = type; ModuleName = moduleName; IgnoreCase = option.Binding?.IgnoreCase; Field = option.Binding?.Field; TargetName = option.Binding?.TargetName; TargetType = option.Binding?.TargetType; Include = option.Rule?.Include; Exclude = option.Rule?.Exclude; Tag = option.Rule?.Tag; Configuration = option.Configuration != null ? new Dictionary <string, object>(option.Configuration, StringComparer.OrdinalIgnoreCase) : new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); }
public BaselineScope(ScopeType type, string moduleName, IBaselineSpec option) : base(type, moduleName) { Field = option.Binding?.Field; IgnoreCase = option.Binding?.IgnoreCase; NameSeparator = option?.Binding?.NameSeparator; TargetName = option.Binding?.TargetName; TargetType = option.Binding?.TargetType; UseQualifiedName = option.Binding?.UseQualifiedName; Include = option.Rule?.Include; Exclude = option.Rule?.Exclude; Tag = option.Rule?.Tag; Configuration = option.Configuration != null ? new Dictionary <string, object>(option.Configuration, StringComparer.OrdinalIgnoreCase) : new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); }
/// <summary> /// Load matching values /// </summary> /// <param name="option">A baseline options object to load.</param> /// <param name="properties">One or more indexed properties.</param> internal static void Load(IBaselineSpec option, Dictionary <string, object> properties) { if (properties.TryPopValue("binding.ignorecase", out object value)) { option.Binding.IgnoreCase = bool.Parse(value.ToString()); } if (properties.TryPopValue("binding.field", out value) && value is Hashtable map) { option.Binding.Field = new FieldMap(map); } if (properties.TryPopValue("binding.targetname", out value)) { if (value.GetType().IsArray) { option.Binding.TargetName = ((object[])value).OfType <string>().ToArray(); } else { option.Binding.TargetName = new string[] { value.ToString() } }; } if (properties.TryPopValue("binding.targettype", out value)) { if (value.GetType().IsArray) { option.Binding.TargetType = ((object[])value).OfType <string>().ToArray(); } else { option.Binding.TargetType = new string[] { value.ToString() } }; } if (properties.TryPopValue("rule.include", out value)) { if (value.GetType().IsArray) { option.Rule.Include = ((object[])value).OfType <string>().ToArray(); } else { option.Rule.Include = new string[] { value.ToString() } }; } if (properties.TryPopValue("rule.exclude", out value)) { if (value.GetType().IsArray) { option.Rule.Exclude = ((object[])value).OfType <string>().ToArray(); } else { option.Rule.Exclude = new string[] { value.ToString() } }; } if (properties.TryPopValue("rule.tag", out value) && value is Hashtable tag) { option.Rule.Tag = tag; } // Process configuration values if (properties.Count > 0) { var keys = properties.Keys.ToArray(); for (var i = 0; i < keys.Length; i++) { if (keys[i].Length > 14 && keys[i].StartsWith("Configuration.", StringComparison.OrdinalIgnoreCase)) { option.Configuration[keys[i].Substring(14)] = properties[keys[i]]; } } } } } }