• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 using Grpc.Core.Utils;
18 
19 namespace Grpc.Core
20 {
21     /// <summary>
22     /// Represents RPC result, which consists of <see cref="StatusCode"/> and an optional detail string.
23     /// </summary>
24     public struct Status
25     {
26         /// <summary>
27         /// Default result of a successful RPC. StatusCode=OK, empty details message.
28         /// </summary>
29         public static readonly Status DefaultSuccess = new Status(StatusCode.OK, "");
30 
31         /// <summary>
32         /// Default result of a cancelled RPC. StatusCode=Cancelled, empty details message.
33         /// </summary>
34         public static readonly Status DefaultCancelled = new Status(StatusCode.Cancelled, "");
35 
36         readonly StatusCode statusCode;
37         readonly string detail;
38 
39         /// <summary>
40         /// Creates a new instance of <c>Status</c>.
41         /// </summary>
42         /// <param name="statusCode">Status code.</param>
43         /// <param name="detail">Detail.</param>
StatusGrpc.Core.Status44         public Status(StatusCode statusCode, string detail)
45         {
46             this.statusCode = statusCode;
47             this.detail = detail;
48         }
49 
50         /// <summary>
51         /// Gets the gRPC status code. OK indicates success, all other values indicate an error.
52         /// </summary>
53         public StatusCode StatusCode
54         {
55             get
56             {
57                 return statusCode;
58             }
59         }
60 
61         /// <summary>
62         /// Gets the detail.
63         /// </summary>
64         public string Detail
65         {
66             get
67             {
68                 return detail;
69             }
70         }
71 
72         /// <summary>
73         /// Returns a <see cref="System.String"/> that represents the current <see cref="Grpc.Core.Status"/>.
74         /// </summary>
ToStringGrpc.Core.Status75         public override string ToString()
76         {
77             return string.Format("Status(StatusCode={0}, Detail=\"{1}\")", statusCode, detail);
78         }
79     }
80 }
81