Unit.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. #nullable disable
  5. namespace System.Reactive
  6. {
  7. /// <summary>
  8. /// 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).
  9. /// </summary>
  10. #if !NO_SERIALIZABLE
  11. [Serializable]
  12. #endif
  13. public readonly struct Unit : IEquatable<Unit>
  14. {
  15. /// <summary>
  16. /// Determines whether the specified <see cref="Unit"/> value is equal to the current <see cref="Unit"/>. Because <see cref="Unit"/> has a single value, this always returns <c>true</c>.
  17. /// </summary>
  18. /// <param name="other">An object to compare to the current <see cref="Unit"/> value.</param>
  19. /// <returns>Because <see cref="Unit"/> has a single value, this always returns <c>true</c>.</returns>
  20. public bool Equals(Unit other) => true;
  21. /// <summary>
  22. /// Determines whether the specified System.Object is equal to the current <see cref="Unit"/>.
  23. /// </summary>
  24. /// <param name="obj">The System.Object to compare with the current <see cref="Unit"/>.</param>
  25. /// <returns><c>true</c> if the specified System.Object is a <see cref="Unit"/> value; otherwise, <c>false</c>.</returns>
  26. public override bool Equals(object obj) => obj is Unit;
  27. /// <summary>
  28. /// Returns the hash code for the current <see cref="Unit"/> value.
  29. /// </summary>
  30. /// <returns>A hash code for the current <see cref="Unit"/> value.</returns>
  31. public override int GetHashCode() => 0;
  32. /// <summary>
  33. /// Returns a string representation of the current <see cref="Unit"/> value.
  34. /// </summary>
  35. /// <returns>String representation of the current <see cref="Unit"/> value.</returns>
  36. public override string ToString() => "()";
  37. /// <summary>
  38. /// Determines whether the two specified <see cref="Unit"/> values are equal. Because <see cref="Unit"/> has a single value, this always returns <c>true</c>.
  39. /// </summary>
  40. /// <param name="first">The first <see cref="Unit"/> value to compare.</param>
  41. /// <param name="second">The second <see cref="Unit"/> value to compare.</param>
  42. /// <returns>Because <see cref="Unit"/> has a single value, this always returns <c>true</c>.</returns>
  43. [Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "first", Justification = "Parameter required for operator overloading."), Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "second", Justification = "Parameter required for operator overloading.")]
  44. public static bool operator ==(Unit first, Unit second) => true;
  45. /// <summary>
  46. /// Determines whether the two specified <see cref="Unit"/> values are not equal. Because <see cref="Unit"/> has a single value, this always returns <c>false</c>.
  47. /// </summary>
  48. /// <param name="first">The first <see cref="Unit"/> value to compare.</param>
  49. /// <param name="second">The second <see cref="Unit"/> value to compare.</param>
  50. /// <returns>Because <see cref="Unit"/> has a single value, this always returns <c>false</c>.</returns>
  51. [Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "first", Justification = "Parameter required for operator overloading."), Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "second", Justification = "Parameter required for operator overloading.")]
  52. public static bool operator !=(Unit first, Unit second) => false;
  53. /// <summary>
  54. /// Gets the single <see cref="Unit"/> value.
  55. /// </summary>
  56. public static Unit Default => default;
  57. }
  58. }