Skip to content

Commit 4795681

Browse files
Update methods
1 parent 6448783 commit 4795681

33 files changed

+227
-772
lines changed

src/Grpc.AspNetCore.Web/GrpcWebApplicationBuilderExtensions.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ public static class GrpcWebApplicationBuilderExtensions
3232
/// </summary>
3333
/// <param name="builder">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
3434
/// <returns>A reference to this instance after the operation has completed.</returns>
35-
public static IApplicationBuilder UseGrpcWeb(this IApplicationBuilder builder)
36-
{
37-
return builder.UseGrpcWeb(new GrpcWebOptions());
38-
}
35+
public static IApplicationBuilder UseGrpcWeb(this IApplicationBuilder builder) => builder.UseGrpcWeb(new GrpcWebOptions());
3936

4037
/// <summary>
4138
/// Adds gRPC-Web middleware to the specified <see cref="IApplicationBuilder"/>.

src/Grpc.Auth/GoogleAuthInterceptors.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public static AsyncAuthInterceptor FromCredential(ITokenAccess credential)
5858
/// <param name="credential">The credential to use to obtain access tokens.</param>
5959
/// <returns>The interceptor.</returns>
6060
public static AsyncAuthInterceptor FromCredential(ITokenAccessWithHeaders credential)
61-
{
62-
return new AsyncAuthInterceptor(async (context, metadata) =>
61+
=> new AsyncAuthInterceptor(async (context, metadata) =>
6362
{
6463
AccessTokenWithHeaders tokenAndHeaders = await credential.GetAccessTokenWithHeadersForRequestAsync(context.ServiceUrl, CancellationToken.None).ConfigureAwait(false);
6564
metadata.Add(CreateBearerTokenHeader(tokenAndHeaders.AccessToken));
@@ -71,7 +70,6 @@ public static AsyncAuthInterceptor FromCredential(ITokenAccessWithHeaders creden
7170
}
7271
}
7372
});
74-
}
7573

7674
/// <summary>
7775
/// Creates an <see cref="AsyncAuthInterceptor"/> that will use given access token as authorization.
@@ -89,15 +87,10 @@ public static AsyncAuthInterceptor FromAccessToken(string accessToken)
8987
}
9088

9189
private static Metadata.Entry CreateBearerTokenHeader(string accessToken)
92-
{
93-
return new Metadata.Entry(AuthorizationHeader, Schema + " " + accessToken);
94-
}
90+
=> new Metadata.Entry(AuthorizationHeader, Schema + " " + accessToken);
9591

9692
/// <summary>
9793
/// Framework independent equivalent of <c>Task.CompletedTask</c>.
9894
/// </summary>
99-
private static Task GetCompletedTask()
100-
{
101-
return Task.CompletedTask;
102-
}
95+
private static Task GetCompletedTask() => Task.CompletedTask;
10396
}

src/Grpc.Auth/GoogleGrpcCredentials.cs

+3-9
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public static async Task<ChannelCredentials> GetApplicationDefaultAsync()
5151
/// <param name="accessToken">OAuth2 access token.</param>
5252
/// <returns>The <c>CallCredentials</c> instance.</returns>
5353
public static CallCredentials FromAccessToken(string accessToken)
54-
{
55-
return CallCredentials.FromInterceptor(GoogleAuthInterceptors.FromAccessToken(accessToken));
56-
}
54+
=> CallCredentials.FromInterceptor(GoogleAuthInterceptors.FromAccessToken(accessToken));
5755

5856
/// <summary>
5957
/// Converts a <c>ITokenAccess</c> (e.g. <c>GoogleCredential</c>) object
@@ -62,9 +60,7 @@ public static CallCredentials FromAccessToken(string accessToken)
6260
/// <param name="credential">The credential to use to obtain access tokens.</param>
6361
/// <returns>The <c>CallCredentials</c> instance.</returns>
6462
public static CallCredentials ToCallCredentials(this ITokenAccess credential)
65-
{
66-
return CallCredentials.FromInterceptor(GoogleAuthInterceptors.FromCredential(credential));
67-
}
63+
=> CallCredentials.FromInterceptor(GoogleAuthInterceptors.FromCredential(credential));
6864

6965
/// <summary>
7066
/// Converts a <c>ITokenAccess</c> (e.g. <c>GoogleCredential</c>) object
@@ -74,7 +70,5 @@ public static CallCredentials ToCallCredentials(this ITokenAccess credential)
7470
/// <param name="googleCredential">The credential to use to obtain access tokens.</param>
7571
/// <returns>>The <c>ChannelCredentials</c> instance.</returns>
7672
public static ChannelCredentials ToChannelCredentials(this ITokenAccess googleCredential)
77-
{
78-
return ChannelCredentials.Create(new SslCredentials(), googleCredential.ToCallCredentials());
79-
}
73+
=> ChannelCredentials.Create(new SslCredentials(), googleCredential.ToCallCredentials());
8074
}

src/Grpc.Core.Api/AsyncAuthInterceptor.cs

+3-12
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,15 @@ public AuthInterceptorContext(string serviceUrl, string methodName, Cancellation
5959
/// <summary>
6060
/// The fully qualified service URL for the RPC being called.
6161
/// </summary>
62-
public string ServiceUrl
63-
{
64-
get { return serviceUrl; }
65-
}
62+
public string ServiceUrl => serviceUrl;
6663

6764
/// <summary>
6865
/// The method name of the RPC being called.
6966
/// </summary>
70-
public string MethodName
71-
{
72-
get { return methodName; }
73-
}
67+
public string MethodName => methodName;
7468

7569
/// <summary>
7670
/// The cancellation token of the RPC being called.
7771
/// </summary>
78-
public CancellationToken CancellationToken
79-
{
80-
get { return cancellationToken; }
81-
}
72+
public CancellationToken CancellationToken => cancellationToken;
8273
}

src/Grpc.Core.Api/AsyncClientStreamingCall.cs

+10-47
Original file line numberDiff line numberDiff line change
@@ -84,45 +84,24 @@ public AsyncClientStreamingCall(IClientStreamWriter<TRequest> requestStream,
8484
/// <summary>
8585
/// Asynchronous call result.
8686
/// </summary>
87-
public Task<TResponse> ResponseAsync
88-
{
89-
get
90-
{
91-
return this.responseAsync;
92-
}
93-
}
87+
public Task<TResponse> ResponseAsync => this.responseAsync;
9488

9589
/// <summary>
9690
/// Asynchronous access to response headers.
9791
/// </summary>
98-
public Task<Metadata> ResponseHeadersAsync
99-
{
100-
get
101-
{
102-
return callState.ResponseHeadersAsync();
103-
}
104-
}
92+
public Task<Metadata> ResponseHeadersAsync => callState.ResponseHeadersAsync();
10593

10694
/// <summary>
10795
/// Async stream to send streaming requests.
10896
/// </summary>
109-
public IClientStreamWriter<TRequest> RequestStream
110-
{
111-
get
112-
{
113-
return requestStream;
114-
}
115-
}
97+
public IClientStreamWriter<TRequest> RequestStream => requestStream;
11698

11799
/// <summary>
118100
/// Gets an awaiter used to await this <see cref="AsyncClientStreamingCall{TRequest,TResponse}"/>.
119101
/// </summary>
120102
/// <returns>An awaiter instance.</returns>
121103
/// <remarks>This method is intended for compiler use rather than use directly in code.</remarks>
122-
public TaskAwaiter<TResponse> GetAwaiter()
123-
{
124-
return responseAsync.GetAwaiter();
125-
}
104+
public TaskAwaiter<TResponse> GetAwaiter() => responseAsync.GetAwaiter();
126105

127106
/// <summary>
128107
/// Configures an awaiter used to await this <see cref="AsyncClientStreamingCall{TRequest,TResponse}"/>.
@@ -132,27 +111,19 @@ public TaskAwaiter<TResponse> GetAwaiter()
132111
/// </param>
133112
/// <returns>An object used to await this task.</returns>
134113
public ConfiguredTaskAwaitable<TResponse> ConfigureAwait(bool continueOnCapturedContext)
135-
{
136-
return responseAsync.ConfigureAwait(continueOnCapturedContext);
137-
}
114+
=> responseAsync.ConfigureAwait(continueOnCapturedContext);
138115

139116
/// <summary>
140117
/// Gets the call status if the call has already finished.
141118
/// Throws InvalidOperationException otherwise.
142119
/// </summary>
143-
public Status GetStatus()
144-
{
145-
return callState.GetStatus();
146-
}
120+
public Status GetStatus() => callState.GetStatus();
147121

148122
/// <summary>
149123
/// Gets the call trailing metadata if the call has already finished.
150124
/// Throws InvalidOperationException otherwise.
151125
/// </summary>
152-
public Metadata GetTrailers()
153-
{
154-
return callState.GetTrailers();
155-
}
126+
public Metadata GetTrailers() => callState.GetTrailers();
156127

157128
/// <summary>
158129
/// Provides means to cleanup after the call.
@@ -164,21 +135,13 @@ public Metadata GetTrailers()
164135
/// Normally, there is no need for you to dispose the call unless you want to utilize the
165136
/// "Cancel" semantics of invoking <c>Dispose</c>.
166137
/// </remarks>
167-
public void Dispose()
168-
{
169-
callState.Dispose();
170-
}
138+
public void Dispose() => callState.Dispose();
171139

172140
private string DebuggerToString() => CallDebuggerHelpers.DebuggerToString(callState);
173141

174-
private sealed class AsyncClientStreamingCallDebugView
142+
private sealed class AsyncClientStreamingCallDebugView(AsyncClientStreamingCall<TRequest, TResponse> call)
175143
{
176-
private readonly AsyncClientStreamingCall<TRequest, TResponse> _call;
177-
178-
public AsyncClientStreamingCallDebugView(AsyncClientStreamingCall<TRequest, TResponse> call)
179-
{
180-
_call = call;
181-
}
144+
private readonly AsyncClientStreamingCall<TRequest, TResponse> _call = call;
182145

183146
public bool IsComplete => CallDebuggerHelpers.GetStatus(_call.callState) != null;
184147
public Status? Status => CallDebuggerHelpers.GetStatus(_call.callState);

src/Grpc.Core.Api/AsyncDuplexStreamingCall.cs

+8-40
Original file line numberDiff line numberDiff line change
@@ -83,53 +83,29 @@ public AsyncDuplexStreamingCall(IClientStreamWriter<TRequest> requestStream,
8383
/// <summary>
8484
/// Async stream to read streaming responses.
8585
/// </summary>
86-
public IAsyncStreamReader<TResponse> ResponseStream
87-
{
88-
get
89-
{
90-
return responseStream;
91-
}
92-
}
86+
public IAsyncStreamReader<TResponse> ResponseStream => responseStream;
9387

9488
/// <summary>
9589
/// Async stream to send streaming requests.
9690
/// </summary>
97-
public IClientStreamWriter<TRequest> RequestStream
98-
{
99-
get
100-
{
101-
return requestStream;
102-
}
103-
}
91+
public IClientStreamWriter<TRequest> RequestStream => requestStream;
10492

10593
/// <summary>
10694
/// Asynchronous access to response headers.
10795
/// </summary>
108-
public Task<Metadata> ResponseHeadersAsync
109-
{
110-
get
111-
{
112-
return callState.ResponseHeadersAsync();
113-
}
114-
}
96+
public Task<Metadata> ResponseHeadersAsync => callState.ResponseHeadersAsync();
11597

11698
/// <summary>
11799
/// Gets the call status if the call has already finished.
118100
/// Throws InvalidOperationException otherwise.
119101
/// </summary>
120-
public Status GetStatus()
121-
{
122-
return callState.GetStatus();
123-
}
102+
public Status GetStatus() => callState.GetStatus();
124103

125104
/// <summary>
126105
/// Gets the call trailing metadata if the call has already finished.
127106
/// Throws InvalidOperationException otherwise.
128107
/// </summary>
129-
public Metadata GetTrailers()
130-
{
131-
return callState.GetTrailers();
132-
}
108+
public Metadata GetTrailers() => callState.GetTrailers();
133109

134110
/// <summary>
135111
/// Provides means to cleanup after the call.
@@ -141,21 +117,13 @@ public Metadata GetTrailers()
141117
/// Normally, there is no need for you to dispose the call unless you want to utilize the
142118
/// "Cancel" semantics of invoking <c>Dispose</c>.
143119
/// </remarks>
144-
public void Dispose()
145-
{
146-
callState.Dispose();
147-
}
120+
public void Dispose() => callState.Dispose();
148121

149122
private string DebuggerToString() => CallDebuggerHelpers.DebuggerToString(callState);
150123

151-
private sealed class AsyncDuplexStreamingCallDebugView
124+
private sealed class AsyncDuplexStreamingCallDebugView(AsyncDuplexStreamingCall<TRequest, TResponse> call)
152125
{
153-
private readonly AsyncDuplexStreamingCall<TRequest, TResponse> _call;
154-
155-
public AsyncDuplexStreamingCallDebugView(AsyncDuplexStreamingCall<TRequest, TResponse> call)
156-
{
157-
_call = call;
158-
}
126+
private readonly AsyncDuplexStreamingCall<TRequest, TResponse> _call = call;
159127

160128
public bool IsComplete => CallDebuggerHelpers.GetStatus(_call.callState) != null;
161129
public Status? Status => CallDebuggerHelpers.GetStatus(_call.callState);

src/Grpc.Core.Api/AsyncServerStreamingCall.cs

+7-33
Original file line numberDiff line numberDiff line change
@@ -75,42 +75,24 @@ public AsyncServerStreamingCall(IAsyncStreamReader<TResponse> responseStream,
7575
/// <summary>
7676
/// Async stream to read streaming responses.
7777
/// </summary>
78-
public IAsyncStreamReader<TResponse> ResponseStream
79-
{
80-
get
81-
{
82-
return responseStream;
83-
}
84-
}
78+
public IAsyncStreamReader<TResponse> ResponseStream => responseStream;
8579

8680
/// <summary>
8781
/// Asynchronous access to response headers.
8882
/// </summary>
89-
public Task<Metadata> ResponseHeadersAsync
90-
{
91-
get
92-
{
93-
return callState.ResponseHeadersAsync();
94-
}
95-
}
83+
public Task<Metadata> ResponseHeadersAsync => callState.ResponseHeadersAsync();
9684

9785
/// <summary>
9886
/// Gets the call status if the call has already finished.
9987
/// Throws InvalidOperationException otherwise.
10088
/// </summary>
101-
public Status GetStatus()
102-
{
103-
return callState.GetStatus();
104-
}
89+
public Status GetStatus() => callState.GetStatus();
10590

10691
/// <summary>
10792
/// Gets the call trailing metadata if the call has already finished.
10893
/// Throws InvalidOperationException otherwise.
10994
/// </summary>
110-
public Metadata GetTrailers()
111-
{
112-
return callState.GetTrailers();
113-
}
95+
public Metadata GetTrailers() => callState.GetTrailers();
11496

11597
/// <summary>
11698
/// Provides means to cleanup after the call.
@@ -122,21 +104,13 @@ public Metadata GetTrailers()
122104
/// Normally, there is no need for you to dispose the call unless you want to utilize the
123105
/// "Cancel" semantics of invoking <c>Dispose</c>.
124106
/// </remarks>
125-
public void Dispose()
126-
{
127-
callState.Dispose();
128-
}
107+
public void Dispose() => callState.Dispose();
129108

130109
private string DebuggerToString() => CallDebuggerHelpers.DebuggerToString(callState);
131110

132-
private sealed class AsyncServerStreamingCallDebugView
111+
private sealed class AsyncServerStreamingCallDebugView(AsyncServerStreamingCall<TResponse> call)
133112
{
134-
private readonly AsyncServerStreamingCall<TResponse> _call;
135-
136-
public AsyncServerStreamingCallDebugView(AsyncServerStreamingCall<TResponse> call)
137-
{
138-
_call = call;
139-
}
113+
private readonly AsyncServerStreamingCall<TResponse> _call = call;
140114

141115
public bool IsComplete => CallDebuggerHelpers.GetStatus(_call.callState) != null;
142116
public Status? Status => CallDebuggerHelpers.GetStatus(_call.callState);

0 commit comments

Comments
 (0)