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

85 lines
1.9 KiB

  1. using Apewer.Internals;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace Apewer.Internals
  6. {
  7. /// <summary>文本对。</summary>
  8. internal struct TextPair
  9. {
  10. private string _key;
  11. private string _value;
  12. public string Key
  13. {
  14. get { return _key ?? ""; }
  15. set { _key = value ?? ""; }
  16. }
  17. public string Value
  18. {
  19. get { return _value ?? ""; }
  20. set { _value = value ?? ""; }
  21. }
  22. public bool NotEmpty
  23. {
  24. get { return !string.IsNullOrEmpty(_key) && !string.IsNullOrEmpty(_value); }
  25. }
  26. public bool EmptyBoth
  27. {
  28. get { return string.IsNullOrEmpty(_key) && string.IsNullOrEmpty(_value); }
  29. }
  30. public bool EmptyKey
  31. {
  32. get { return string.IsNullOrEmpty(_key); }
  33. }
  34. public bool EmptyValue
  35. {
  36. get { return string.IsNullOrEmpty(_value); }
  37. }
  38. public TextPair(string argKey)
  39. {
  40. _key = argKey ?? "";
  41. _value = "";
  42. }
  43. public TextPair(string argKey, string argValue)
  44. {
  45. _key = argKey ?? "";
  46. _value = argValue ?? "";
  47. }
  48. public override int GetHashCode()
  49. {
  50. var merge = TextGenerator.Merge(_key, " : ", _value);
  51. var hashcode = merge.GetHashCode();
  52. return hashcode;
  53. }
  54. public override bool Equals(object obj)
  55. {
  56. if (obj == null) return false;
  57. return (_key == ((TextPair)obj)._key) && (_value == ((TextPair)obj)._value);
  58. }
  59. public static bool operator ==(TextPair a, TextPair b)
  60. {
  61. return (a._key == b._key) && (a._value == b._value);
  62. }
  63. public static bool operator !=(TextPair a, TextPair b)
  64. {
  65. return (a._key != b._key) || (a._value != b._value);
  66. }
  67. }
  68. }