BsonMinKey.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* Copyright 2010-2014 MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. namespace MongoDB.Bson
  17. {
  18. /// <summary>
  19. /// Represents the BSON MinKey value.
  20. /// </summary>
  21. [Serializable]
  22. public class BsonMinKey : BsonValue, IComparable<BsonMinKey>, IEquatable<BsonMinKey>
  23. {
  24. // private static fields
  25. private static BsonMinKey __value = new BsonMinKey();
  26. // constructors
  27. // private so only the singleton instance can be created
  28. private BsonMinKey()
  29. : base(BsonType.MinKey)
  30. {
  31. }
  32. // public operators
  33. /// <summary>
  34. /// Compares two BsonMinKey values.
  35. /// </summary>
  36. /// <param name="lhs">The first BsonMinKey.</param>
  37. /// <param name="rhs">The other BsonMinKey.</param>
  38. /// <returns>True if the two BsonMinKey values are not equal according to ==.</returns>
  39. public static bool operator !=(BsonMinKey lhs, BsonMinKey rhs)
  40. {
  41. return !(lhs == rhs);
  42. }
  43. /// <summary>
  44. /// Compares two BsonMinKey values.
  45. /// </summary>
  46. /// <param name="lhs">The first BsonMinKey.</param>
  47. /// <param name="rhs">The other BsonMinKey.</param>
  48. /// <returns>True if the two BsonMinKey values are equal according to ==.</returns>
  49. public static bool operator ==(BsonMinKey lhs, BsonMinKey rhs)
  50. {
  51. if (object.ReferenceEquals(lhs, null)) { return object.ReferenceEquals(rhs, null); }
  52. return lhs.Equals(rhs);
  53. }
  54. // public static properties
  55. /// <summary>
  56. /// Gets the singleton instance of BsonMinKey.
  57. /// </summary>
  58. public static BsonMinKey Value { get { return __value; } }
  59. // public methods
  60. /// <summary>
  61. /// Compares this BsonMinKey to another BsonMinKey.
  62. /// </summary>
  63. /// <param name="other">The other BsonMinKey.</param>
  64. /// <returns>A 32-bit signed integer that indicates whether this BsonMinKey is less than, equal to, or greather than the other.</returns>
  65. public int CompareTo(BsonMinKey other)
  66. {
  67. if (other == null) { return 1; }
  68. return 0; // it's a singleton
  69. }
  70. /// <summary>
  71. /// Compares the BsonMinKey to another BsonValue.
  72. /// </summary>
  73. /// <param name="other">The other BsonValue.</param>
  74. /// <returns>A 32-bit signed integer that indicates whether this BsonMinKey is less than, equal to, or greather than the other BsonValue.</returns>
  75. public override int CompareTo(BsonValue other)
  76. {
  77. if (other == null) { return 1; }
  78. if (other is BsonMinKey) { return 0; }
  79. return -1;
  80. }
  81. /// <summary>
  82. /// Compares this BsonMinKey to another BsonMinKey.
  83. /// </summary>
  84. /// <param name="rhs">The other BsonMinKey.</param>
  85. /// <returns>True if the two BsonMinKey values are equal.</returns>
  86. public bool Equals(BsonMinKey rhs)
  87. {
  88. if (object.ReferenceEquals(rhs, null) || GetType() != rhs.GetType()) { return false; }
  89. return true; // it's a singleton
  90. }
  91. /// <summary>
  92. /// Compares this BsonMinKey to another object.
  93. /// </summary>
  94. /// <param name="obj">The other object.</param>
  95. /// <returns>True if the other object is a BsonMinKey and equal to this one.</returns>
  96. public override bool Equals(object obj)
  97. {
  98. return Equals(obj as BsonMinKey); // works even if obj is null or of a different type
  99. }
  100. /// <summary>
  101. /// Gets the hash code.
  102. /// </summary>
  103. /// <returns>The hash code.</returns>
  104. public override int GetHashCode()
  105. {
  106. return BsonType.GetHashCode();
  107. }
  108. /// <summary>
  109. /// Returns a string representation of the value.
  110. /// </summary>
  111. /// <returns>A string representation of the value.</returns>
  112. public override string ToString()
  113. {
  114. return "BsonMinKey";
  115. }
  116. }
  117. }