Status.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #region Copyright notice and license
  2. // Copyright 2015 gRPC authors.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using Grpc.Core.Utils;
  17. namespace Grpc.Core
  18. {
  19. /// <summary>
  20. /// Represents RPC result, which consists of <see cref="StatusCode"/> and an optional detail string.
  21. /// </summary>
  22. public struct Status
  23. {
  24. /// <summary>
  25. /// Default result of a successful RPC. StatusCode=OK, empty details message.
  26. /// </summary>
  27. public static readonly Status DefaultSuccess = new Status(StatusCode.OK, "");
  28. /// <summary>
  29. /// Default result of a cancelled RPC. StatusCode=Cancelled, empty details message.
  30. /// </summary>
  31. public static readonly Status DefaultCancelled = new Status(StatusCode.Cancelled, "");
  32. readonly StatusCode statusCode;
  33. readonly string detail;
  34. /// <summary>
  35. /// Creates a new instance of <c>Status</c>.
  36. /// </summary>
  37. /// <param name="statusCode">Status code.</param>
  38. /// <param name="detail">Detail.</param>
  39. public Status(StatusCode statusCode, string detail)
  40. {
  41. this.statusCode = statusCode;
  42. this.detail = detail;
  43. }
  44. /// <summary>
  45. /// Gets the gRPC status code. OK indicates success, all other values indicate an error.
  46. /// </summary>
  47. public StatusCode StatusCode
  48. {
  49. get
  50. {
  51. return statusCode;
  52. }
  53. }
  54. /// <summary>
  55. /// Gets the detail.
  56. /// </summary>
  57. public string Detail
  58. {
  59. get
  60. {
  61. return detail;
  62. }
  63. }
  64. /// <summary>
  65. /// Returns a <see cref="System.String"/> that represents the current <see cref="Grpc.Core.Status"/>.
  66. /// </summary>
  67. public override string ToString()
  68. {
  69. return string.Format("Status(StatusCode={0}, Detail=\"{1}\")", statusCode, detail);
  70. }
  71. }
  72. }