Skip to content

Commit e270f81

Browse files
authored
Enable nullable throughout solution (#2102)
1 parent 6bf4482 commit e270f81

35 files changed

+149
-225
lines changed

perf/benchmarkapps/QpsWorker/Infrastructure/ClientRunner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private Task RunClientAsync(GrpcChannel channel, IInterarrivalTimer timer)
304304
return RunGenericStreamingAsync(channel, timer);
305305
}
306306

307-
GrpcPreconditions.CheckNotNull(_payloadConfig.SimpleParams);
307+
GrpcPreconditions.CheckNotNull(_payloadConfig.SimpleParams, "SimpleParams");
308308
if (_clientType == ClientType.SyncClient)
309309
{
310310
GrpcPreconditions.CheckArgument(_rpcType == RpcType.Unary, "Sync client can only be used for Unary calls in C#");
@@ -326,7 +326,7 @@ private Task RunClientAsync(GrpcChannel channel, IInterarrivalTimer timer)
326326

327327
private SimpleRequest CreateSimpleRequest()
328328
{
329-
GrpcPreconditions.CheckNotNull(_payloadConfig.SimpleParams);
329+
GrpcPreconditions.CheckNotNull(_payloadConfig.SimpleParams, "SimpleParams");
330330
return new SimpleRequest
331331
{
332332
Payload = CreateZerosPayload(_payloadConfig.SimpleParams.ReqSize),

src/Grpc.Auth/GoogleAuthInterceptors.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
#endregion
1818

19-
using System.Threading;
20-
using System.Threading.Tasks;
21-
2219
using Google.Apis.Auth.OAuth2;
2320
using Grpc.Core;
2421
using Grpc.Core.Utils;
@@ -83,7 +80,7 @@ public static AsyncAuthInterceptor FromCredential(ITokenAccessWithHeaders creden
8380
/// <returns>The interceptor.</returns>
8481
public static AsyncAuthInterceptor FromAccessToken(string accessToken)
8582
{
86-
GrpcPreconditions.CheckNotNull(accessToken);
83+
GrpcPreconditions.CheckNotNull(accessToken, nameof(accessToken));
8784
return new AsyncAuthInterceptor((context, metadata) =>
8885
{
8986
metadata.Add(CreateBearerTokenHeader(accessToken));

src/Grpc.Core.Api/AsyncAuthInterceptor.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616

1717
#endregion
1818

19-
using System;
20-
using System.Collections.Generic;
2119
using System.Threading.Tasks;
22-
23-
using Grpc.Core.Internal;
2420
using Grpc.Core.Utils;
2521

2622
namespace Grpc.Core;
@@ -46,8 +42,8 @@ public class AuthInterceptorContext
4642
/// </summary>
4743
public AuthInterceptorContext(string serviceUrl, string methodName)
4844
{
49-
this.serviceUrl = GrpcPreconditions.CheckNotNull(serviceUrl);
50-
this.methodName = GrpcPreconditions.CheckNotNull(methodName);
45+
this.serviceUrl = GrpcPreconditions.CheckNotNull(serviceUrl, nameof(serviceUrl));
46+
this.methodName = GrpcPreconditions.CheckNotNull(methodName, nameof(methodName));
5147
}
5248

5349
/// <summary>

src/Grpc.Core.Api/AuthContext.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#endregion
1818

19-
using System;
2019
using System.Collections.Generic;
2120
using System.Linq;
2221
using Grpc.Core.Utils;
@@ -31,8 +30,8 @@ namespace Grpc.Core;
3130
/// </summary>
3231
public class AuthContext
3332
{
34-
string? peerIdentityPropertyName;
35-
Dictionary<string, List<AuthProperty>> properties;
33+
private readonly string? peerIdentityPropertyName;
34+
private readonly Dictionary<string, List<AuthProperty>> properties;
3635

3736
/// <summary>
3837
/// Initializes a new instance of the <see cref="T:Grpc.Core.AuthContext"/> class.
@@ -42,7 +41,7 @@ public class AuthContext
4241
public AuthContext(string? peerIdentityPropertyName, Dictionary<string, List<AuthProperty>> properties)
4342
{
4443
this.peerIdentityPropertyName = peerIdentityPropertyName;
45-
this.properties = GrpcPreconditions.CheckNotNull(properties);
44+
this.properties = GrpcPreconditions.CheckNotNull(properties, nameof(properties));
4645
}
4746

4847
/// <summary>
@@ -101,8 +100,7 @@ public IEnumerable<AuthProperty> Properties
101100
/// </summary>
102101
public IEnumerable<AuthProperty> FindPropertiesByName(string propertyName)
103102
{
104-
List<AuthProperty>? result;
105-
if (!properties.TryGetValue(propertyName, out result))
103+
if (!properties.TryGetValue(propertyName, out var result))
106104
{
107105
return Enumerable.Empty<AuthProperty>();
108106
}

src/Grpc.Core.Api/AuthProperty.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ namespace Grpc.Core;
2929
public class AuthProperty
3030
{
3131
static readonly Encoding EncodingUTF8 = System.Text.Encoding.UTF8;
32-
string name;
33-
byte[] valueBytes;
34-
string? lazyValue;
32+
33+
private readonly string name;
34+
private readonly byte[] valueBytes;
35+
private string? lazyValue;
3536

3637
private AuthProperty(string name, byte[] valueBytes)
3738
{
38-
this.name = GrpcPreconditions.CheckNotNull(name);
39-
this.valueBytes = GrpcPreconditions.CheckNotNull(valueBytes);
39+
this.name = GrpcPreconditions.CheckNotNull(name, nameof(name));
40+
this.valueBytes = GrpcPreconditions.CheckNotNull(valueBytes, nameof(valueBytes));
4041
}
4142

4243
/// <summary>
@@ -57,7 +58,7 @@ public string Value
5758
{
5859
get
5960
{
60-
return lazyValue ?? (lazyValue = EncodingUTF8.GetString(this.valueBytes));
61+
return lazyValue ??= EncodingUTF8.GetString(this.valueBytes);
6162
}
6263
}
6364

@@ -81,7 +82,7 @@ public byte[] ValueBytes
8182
/// <param name="valueBytes">the binary value of the property</param>
8283
public static AuthProperty Create(string name, byte[] valueBytes)
8384
{
84-
GrpcPreconditions.CheckNotNull(valueBytes);
85+
GrpcPreconditions.CheckNotNull(valueBytes, nameof(valueBytes));
8586
var valueCopy = new byte[valueBytes.Length];
8687
Buffer.BlockCopy(valueBytes, 0, valueCopy, 0, valueBytes.Length);
8788
return new AuthProperty(name, valueCopy);

src/Grpc.Core.Api/CallCredentials.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#endregion
1818

1919
using System.Collections.Generic;
20-
using System.Collections.ObjectModel;
21-
22-
using Grpc.Core.Internal;
2320
using Grpc.Core.Utils;
2421

2522
namespace Grpc.Core;
@@ -78,7 +75,7 @@ private class AsyncAuthInterceptorCredentials : CallCredentials
7875

7976
public AsyncAuthInterceptorCredentials(AsyncAuthInterceptor interceptor)
8077
{
81-
this.interceptor = GrpcPreconditions.CheckNotNull(interceptor);
78+
this.interceptor = GrpcPreconditions.CheckNotNull(interceptor, nameof(interceptor));
8279
}
8380

8481
public override void InternalPopulateConfiguration(CallCredentialsConfiguratorBase configurator, object? state)

src/Grpc.Core.Api/ChannelCredentials.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616

1717
#endregion
1818

19-
using System;
20-
using System.Collections.Generic;
21-
using System.Globalization;
22-
using System.Threading.Tasks;
23-
using Grpc.Core.Internal;
2419
using Grpc.Core.Utils;
2520

2621
namespace Grpc.Core;
@@ -121,8 +116,8 @@ private sealed class CompositeChannelCredentials : ChannelCredentials
121116
/// <param name="callCredentials">channelCredentials to compose</param>
122117
public CompositeChannelCredentials(ChannelCredentials channelCredentials, CallCredentials callCredentials)
123118
{
124-
this.channelCredentials = GrpcPreconditions.CheckNotNull(channelCredentials);
125-
this.callCredentials = GrpcPreconditions.CheckNotNull(callCredentials);
119+
this.channelCredentials = GrpcPreconditions.CheckNotNull(channelCredentials, nameof(channelCredentials));
120+
this.callCredentials = GrpcPreconditions.CheckNotNull(callCredentials, nameof(callCredentials));
126121
}
127122

128123
public override void InternalPopulateConfiguration(ChannelCredentialsConfiguratorBase configurator, object state)

src/Grpc.Core.Api/ClientBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ internal ClientBaseConfigurationInfo(string? host, CallOptions callOptions)
212212

213213
internal ClientBaseConfiguration(CallInvoker undecoratedCallInvoker, string? host)
214214
{
215-
this.undecoratedCallInvoker = GrpcPreconditions.CheckNotNull(undecoratedCallInvoker);
215+
this.undecoratedCallInvoker = GrpcPreconditions.CheckNotNull(undecoratedCallInvoker, nameof(undecoratedCallInvoker));
216216
this.host = host;
217217
}
218218

src/Grpc.Core.Api/Grpc.Core.Api.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<PackageReadmeFile>README.md</PackageReadmeFile>
1010

1111
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
12-
<Nullable>enable</Nullable>
1312
<!-- grpc-dotnet global usings break the build. -->
1413
<ImplicitUsings>disable</ImplicitUsings>
1514
</PropertyGroup>

src/Grpc.Core.Api/Metadata.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public void Add(string key, byte[] valueBytes)
149149

150150
#region IList members
151151

152-
153152
/// <summary>
154153
/// <see cref="T:IList`1"/>
155154
/// </summary>
@@ -163,7 +162,7 @@ public int IndexOf(Metadata.Entry item)
163162
/// </summary>
164163
public void Insert(int index, Metadata.Entry item)
165164
{
166-
GrpcPreconditions.CheckNotNull(item);
165+
GrpcPreconditions.CheckNotNull(item, nameof(item));
167166
CheckWriteable();
168167
entries.Insert(index, item);
169168
}
@@ -189,7 +188,7 @@ public Metadata.Entry this[int index]
189188

190189
set
191190
{
192-
GrpcPreconditions.CheckNotNull(value);
191+
GrpcPreconditions.CheckNotNull(value, nameof(value));
193192
CheckWriteable();
194193
entries[index] = value;
195194
}
@@ -200,7 +199,7 @@ public Metadata.Entry this[int index]
200199
/// </summary>
201200
public void Add(Metadata.Entry item)
202201
{
203-
GrpcPreconditions.CheckNotNull(item);
202+
GrpcPreconditions.CheckNotNull(item, nameof(item));
204203
CheckWriteable();
205204
entries.Add(item);
206205
}
@@ -462,8 +461,10 @@ private static bool IsValidKey(string input, out bool isLowercase)
462461
'0' <= c && c <= '9' ||
463462
c == '.' ||
464463
c == '_' ||
465-
c == '-' )
464+
c == '-')
465+
{
466466
continue;
467+
}
467468

468469
if ('A' <= c && c <= 'Z')
469470
{

0 commit comments

Comments
 (0)