DictionaryExpand.cs 800 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace MECF.Framework.Common.Utilities
  7. {
  8. public static class DictionaryExpand
  9. {
  10. public static void AddRange<T, S>(this Dictionary<T, S> source, Dictionary<T, S> collection)
  11. {
  12. if (collection == null)
  13. {
  14. throw new ArgumentNullException("Collection is null");
  15. }
  16. foreach (var item in collection)
  17. {
  18. if (!source.ContainsKey(item.Key))
  19. {
  20. source.Add(item.Key, item.Value);
  21. }
  22. else
  23. {
  24. // handle duplicate key issue here
  25. }
  26. }
  27. }
  28. }
  29. }