Unit.cs 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <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>.
  16. /// </summary>
  17. /// <param name="other">An object to compare to the current <see cref="Unit"/> value.</param>
  18. /// <returns>Because <see cref="Unit"/> has a single value, this always returns <c>true</c>.</returns>
  19. public bool Equals(Unit other) => true;
  20. /// <summary>
  21. /// Determines whether the specified System.Object is equal to the current <see cref="Unit"/>.
  22. /// </summary>
  23. /// <param name="obj">The System.Object to compare with the current <see cref="Unit"/>.</param>
  24. /// <returns><c>true</c> if the specified System.Object is a <see cref="Unit"/> value; otherwise, <c>false</c>.</returns>
  25. public override bool Equals(object obj) => obj is Unit;
  26. /// <summary>
  27. /// Returns the hash code for the current <see cref="Unit"/> value.
  28. /// </summary>
  29. /// <returns>A hash code for the current <see cref="Unit"/> value.</returns>
  30. public override int GetHashCode() => 0;
  31. /// <summary>
  32. /// Returns a string representation of the current <see cref="Unit"/> value.
  33. /// </summary>
  34. /// <returns>String representation of the current <see cref="Unit"/> value.</returns>
  35. public override string ToString() => "()";
  36. /// <summary>
  37. /// 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>.
  38. /// </summary>
  39. /// <param name="first">The first <see cref="Unit"/> value to compare.</param>
  40. /// <param name="second">The second <see cref="Unit"/> value to compare.</param>
  41. /// <returns>Because <see cref="Unit"/> has a single value, this always returns <c>true</c>.</returns>
  42. [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.")]
  43. public static bool operator ==(Unit first, Unit second) => true;
  44. /// <summary>
  45. /// 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>.
  46. /// </summary>
  47. /// <param name="first">The first <see cref="Unit"/> value to compare.</param>
  48. /// <param name="second">The second <see cref="Unit"/> value to compare.</param>
  49. /// <returns>Because <see cref="Unit"/> has a single value, this always returns <c>false</c>.</returns>
  50. [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.")]
  51. public static bool operator !=(Unit first, Unit second) => false;
  52. /// <summary>
  53. /// Gets the single <see cref="Unit"/> value.
  54. /// </summary>
  55. public static Unit Default => default(Unit);
  56. }
  57. }