PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/ResourceManagement.ObjectModel/RmBinary.cs

#
C# | 138 lines | 115 code | 20 blank | 3 comment | 24 complexity | 57a202320b66fdfc09a997ade1be3571 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Microsoft.ResourceManagement.ObjectModel
  6. {
  7. public class RmBinary : IComparable, IComparable<RmBinary>
  8. {
  9. byte[] value;
  10. public RmBinary()
  11. {
  12. this.value = new byte[0];
  13. }
  14. public RmBinary(String value)
  15. {
  16. this.Value = value;
  17. }
  18. /// <summary>
  19. /// The string must be supported by the DateTime class
  20. /// </summary>
  21. public String Value
  22. {
  23. get
  24. {
  25. return this.ToString();
  26. }
  27. set
  28. {
  29. if (value != null)
  30. {
  31. this.value = UnicodeEncoding.UTF8.GetBytes(value);
  32. }
  33. else
  34. {
  35. this.value = new byte[0];
  36. }
  37. }
  38. }
  39. public byte[] ValueAsBinary
  40. {
  41. get
  42. {
  43. return this.value;
  44. }
  45. }
  46. public override bool Equals(object obj)
  47. {
  48. RmBinary other = obj as RmBinary;
  49. if (other as Object == null)
  50. return false;
  51. else
  52. return this.ToString().Equals(other.ToString());
  53. }
  54. public override int GetHashCode()
  55. {
  56. return this.ToString().GetHashCode();
  57. }
  58. public override string ToString()
  59. {
  60. return UnicodeEncoding.UTF8.GetString(this.value);
  61. }
  62. #region IComparable Members
  63. public int CompareTo(object obj)
  64. {
  65. if (obj as Object == null)
  66. throw new ArgumentNullException("obj");
  67. return this.CompareTo(obj as RmBinary);
  68. }
  69. public static bool operator ==(RmBinary attrib1, RmBinary attrib2)
  70. {
  71. if (attrib1 as Object == null)
  72. return false;
  73. if (attrib2 as Object == null)
  74. return false;
  75. return attrib1.CompareTo(attrib2) == 0;
  76. }
  77. public static bool operator !=(RmBinary attrib1, RmBinary attrib2)
  78. {
  79. if (attrib1 == null)
  80. return false;
  81. return attrib1.CompareTo(attrib2) != 0;
  82. }
  83. public static bool operator <(RmBinary attrib1, RmBinary attrib2)
  84. {
  85. if (attrib1 == null)
  86. return false;
  87. return attrib1.CompareTo(attrib2) < 0;
  88. }
  89. public static bool operator >(RmBinary attrib1, RmBinary attrib2)
  90. {
  91. if (attrib1 == null)
  92. return false;
  93. return attrib1.CompareTo(attrib2) > 0;
  94. }
  95. public static bool operator <=(RmBinary attrib1, RmBinary attrib2)
  96. {
  97. if (attrib1 == null)
  98. return false;
  99. return attrib1.CompareTo(attrib2) <= 0;
  100. }
  101. public static bool operator >=(RmBinary attrib1, RmBinary attrib2)
  102. {
  103. if (attrib1 == null)
  104. return false;
  105. return attrib1.CompareTo(attrib2) >= 0;
  106. }
  107. #endregion
  108. #region IComparable<RmDateTime> Members
  109. public int CompareTo(RmBinary other)
  110. {
  111. if (other == null)
  112. throw new ArgumentNullException("other");
  113. else
  114. return this.ToString().CompareTo(other.ToString());
  115. }
  116. #endregion
  117. }
  118. }