AsyncCompletedEventArgs.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Date Sign TaskId Description
  3. * ---------- ---- ------- -----------
  4. * 2006-07-31 RMa Generic version of the AsyncCompletedEventArgs should inherit from the non-generic class with same name.
  5. * 2006-03-09 MLa Created
  6. */
  7. using System;
  8. namespace Wayne.Lib
  9. {
  10. /// <summary>
  11. /// Generic event result of an asynchronous command.
  12. /// </summary>
  13. public class AsyncCompletedEventArgs : UserTokenEventArgs
  14. {
  15. #region Fields
  16. private bool success;
  17. #endregion
  18. #region Construction
  19. /// <summary>
  20. /// Construction.
  21. /// </summary>
  22. /// <param name="success">The status of the reservation.</param>
  23. /// <param name="userToken">An optional user token.</param>
  24. public AsyncCompletedEventArgs(bool success, object userToken)
  25. : base(userToken)
  26. {
  27. this.success = success;
  28. }
  29. #endregion
  30. #region Debug methods
  31. /// <summary>
  32. /// Presents the class as a string.
  33. /// </summary>
  34. /// <returns></returns>
  35. public virtual string ToString(string format, IFormatProvider provider)
  36. {
  37. return System.String.Format(provider, "AsyncCompletedEventArgs(Success={0})",
  38. success);
  39. }
  40. /// <summary>
  41. /// Presents the class as a string using the specified culture-specific format information.
  42. /// </summary>
  43. /// <returns></returns>
  44. public virtual string ToString(IFormatProvider provider)
  45. {
  46. return ToString("", provider);
  47. }
  48. /// <summary>
  49. /// Presents the class as a string using a format string.
  50. /// </summary>
  51. /// <returns></returns>
  52. public virtual string ToString(string format)
  53. {
  54. return ToString(format, System.Globalization.CultureInfo.InvariantCulture);
  55. }
  56. /// <summary>
  57. /// Presents the class as a string using a format string and the specified culture-specific format information.
  58. /// </summary>
  59. /// <returns></returns>
  60. public override string ToString()
  61. {
  62. return ToString("", System.Globalization.CultureInfo.InvariantCulture);
  63. }
  64. #endregion
  65. #region Properties
  66. /// <summary>
  67. /// The status of the reservation.
  68. /// </summary>
  69. public bool Success
  70. {
  71. get { return success; }
  72. }
  73. #endregion
  74. }
  75. /// <summary>
  76. /// Generic event result of an asynchronous command with an additional status property.
  77. /// </summary>
  78. public class AsyncCompletedEventArgs<TResult> : AsyncCompletedEventArgs
  79. {
  80. #region Fields
  81. private TResult result;
  82. #endregion
  83. #region Construction
  84. /// <summary>
  85. /// Construction.
  86. /// </summary>
  87. /// <param name="success">The basic status of the command.</param>
  88. /// <param name="result">Refined status of the command.</param>
  89. /// <param name="userToken">An optional user token.</param>
  90. public AsyncCompletedEventArgs(bool success, TResult result, object userToken)
  91. : base(success, userToken)
  92. {
  93. this.result = result;
  94. }
  95. #endregion
  96. #region Debug methods
  97. /// <summary>
  98. /// Presents the class as a string.
  99. /// </summary>
  100. /// <returns></returns>
  101. public override string ToString(string format, IFormatProvider provider)
  102. {
  103. if (result != null)
  104. return String.Format(provider, "AsyncCompletedEventArgs<{0}>(Success={1}, {2})",
  105. typeof(TResult).Name, Success, result);
  106. else
  107. return String.Format(provider, "AsyncCompletedEventArgs<{0}>(Success={1}, null)",
  108. typeof(TResult).Name, Success);
  109. }
  110. #endregion
  111. #region Properties
  112. /// <summary>
  113. /// Refined status of the command.
  114. /// </summary>
  115. public TResult Result
  116. {
  117. get { return result; }
  118. }
  119. #endregion
  120. }
  121. }