Unit.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. namespace System.Reactive
  5. {
  6. /// <summary>
  7. /// Represents a type with a single value. This type is often used to denote the successful completion of a void-returning method (C#) or a Sub procedure (Visual Basic).
  8. /// </summary>
  9. #if !NO_SERIALIZABLE
  10. [Serializable]
  11. #endif
  12. public struct Unit : IEquatable<Unit>
  13. {
  14. /// <summary>
  15. /// Determines whether the specified Unit values is equal to the current Unit. Because Unit has a single value, this always returns true.
  16. /// </summary>
  17. /// <param name="other">An object to compare to the current Unit value.</param>
  18. /// <returns>Because Unit has a single value, this always returns true.</returns>
  19. public bool Equals(Unit other)
  20. {
  21. return true;
  22. }
  23. /// <summary>
  24. /// Determines whether the specified System.Object is equal to the current Unit.
  25. /// </summary>
  26. /// <param name="obj">The System.Object to compare with the current Unit.</param>
  27. /// <returns>true if the specified System.Object is a Unit value; otherwise, false.</returns>
  28. public override bool Equals(object obj)
  29. {
  30. return obj is Unit;
  31. }
  32. /// <summary>
  33. /// Returns the hash code for the current Unit value.
  34. /// </summary>
  35. /// <returns>A hash code for the current Unit value.</returns>
  36. public override int GetHashCode()
  37. {
  38. return 0;
  39. }
  40. /// <summary>
  41. /// Returns a string representation of the current Unit value.
  42. /// </summary>
  43. /// <returns>String representation of the current Unit value.</returns>
  44. public override string ToString()
  45. {
  46. return "()";
  47. }
  48. /// <summary>
  49. /// Determines whether the two specified Unit values are equal. Because Unit has a single value, this always returns true.
  50. /// </summary>
  51. /// <param name="first">The first Unit value to compare.</param>
  52. /// <param name="second">The second Unit value to compare.</param>
  53. /// <returns>Because Unit has a single value, this always returns true.</returns>
  54. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "first", Justification = "Parameter required for operator overloading."), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "second", Justification = "Parameter required for operator overloading.")]
  55. public static bool operator ==(Unit first, Unit second)
  56. {
  57. return true;
  58. }
  59. /// <summary>
  60. /// Determines whether the two specified Unit values are not equal. Because Unit has a single value, this always returns false.
  61. /// </summary>
  62. /// <param name="first">The first Unit value to compare.</param>
  63. /// <param name="second">The second Unit value to compare.</param>
  64. /// <returns>Because Unit has a single value, this always returns false.</returns>
  65. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "first", Justification = "Parameter required for operator overloading."), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "second", Justification = "Parameter required for operator overloading.")]
  66. public static bool operator !=(Unit first, Unit second)
  67. {
  68. return false;
  69. }
  70. static readonly Unit _default = new Unit();
  71. /// <summary>
  72. /// Gets the single unit value.
  73. /// </summary>
  74. public static Unit Default { get { return _default; } }
  75. }
  76. }