You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

DictionaryExtension.cs 879 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using System.Text;
  5. namespace Tensorflow.Common.Extensions
  6. {
  7. public static class DictionaryExtension
  8. {
  9. public static void Deconstruct<T1, T2>(this KeyValuePair<T1, T2> pair, out T1 first, out T2 second)
  10. {
  11. first = pair.Key;
  12. second = pair.Value;
  13. }
  14. public static void Update<T1, T2>(this Dictionary<T1, T2> dic, IDictionary<T1, T2> other)
  15. {
  16. foreach(var (key, value) in other)
  17. {
  18. dic[key] = value;
  19. }
  20. }
  21. public static T2 GetOrDefault<T1, T2>(this Dictionary<T1, T2> dic, T1 key, T2 defaultValue)
  22. {
  23. if (dic.ContainsKey(key))
  24. {
  25. return dic[key];
  26. }
  27. return defaultValue;
  28. }
  29. }
  30. }