PropertiesToolkit.cs 1006 B

1234567891011121314151617181920212223242526272829
  1. namespace EventBus
  2. {
  3. static class PropertiesToolkit
  4. {
  5. /// <summary>
  6. ///
  7. /// </summary>
  8. /// <param name="properties"></param>
  9. /// <returns></returns>
  10. internal static bool FilterRule(this Properties source, Properties properties)
  11. {
  12. if (source == null) return true;
  13. if (source.Count == 0) return true;
  14. if (properties == null) properties = Properties.Default;
  15. if (source.Names.Intersect(properties.Names).Count() != source.Count) return false;
  16. foreach (var name in source.Names)
  17. {
  18. if (!source.TryGetValue(name, out string val)) return false;
  19. else
  20. {
  21. string valstr = properties[name];
  22. if (string.IsNullOrEmpty(valstr)) return false;
  23. return val.Contains(valstr);
  24. }
  25. }
  26. return true;
  27. }
  28. }
  29. }