12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- namespace EventBus
- {
- public sealed class Properties
- {
- internal Dictionary<string, string> Filter { get; set; } = new Dictionary<string, string>();
- public void Add(string name, string value)
- {
- if (Filter.TryGetValue(name, out string val)) Filter[name] = value;
- else Filter.Add(name, value);
- }
- public string this[string name]
- {
- get
- {
- if (Filter.ContainsKey(name)) return Filter[name];
- else return null;
- }
- set
- {
- if (!Filter.ContainsKey(name)) Filter.Add(name, value);
- else Filter[name] = value;
- }
- }
- public bool TryGetValue(string name, out string value) => Filter.TryGetValue(name, out value);
- public int Count => Filter.Count;
- public void Remove(string name) => Filter.Remove(name);
- public void Clear() => Filter.Clear();
- public IEnumerable<string> Values => Filter.Values;
- public IEnumerable<string> Names => Filter.Keys;
- /// <summary>
- /// 比较两个属性是否相等
- /// </summary>
- /// <param name="properties"></param>
- /// <returns></returns>
- internal bool Contains(Properties properties)
- {
- if (properties == null) return false;
- if (properties.Count != Count) return false;
- foreach (var name in Names)
- {
- if (!Filter.TryGetValue(name, out string val)) return false;
- else if (!val.Contains(properties[name])) return false;
- }
- return true;
- }
- public static Properties Default => new Properties();
- }
- }
|