From 82fbf7e88a7031dad63eed89255c59c3f0b093f7 Mon Sep 17 00:00:00 2001 From: forest93 Date: Sat, 21 Mar 2020 19:47:59 +0800 Subject: [PATCH] Fix IDE hints. --- .../AspNetCoreFeatureCollection.cs | 3 +-- JsonRpc.AspNetCore/JsonRpcBuilder.cs | 3 +-- JsonRpc.Commons/Client/Exceptions.cs | 25 +++++++++++++++++++ JsonRpc.Commons/Client/JsonRpcClient.cs | 3 +-- .../Contracts/IJsonValueConverter.cs | 3 +-- JsonRpc.Commons/Messages/MessageEventArgs.cs | 3 +-- .../Server/JsonRpcServerHandler.cs | 3 +-- JsonRpc.Commons/Server/JsonRpcServiceHost.cs | 3 +-- JsonRpc.Commons/Server/RequestContext.cs | 6 ++--- JsonRpc.Streams/ByLineTextMessageReader.cs | 6 ++--- JsonRpc.Streams/ByLineTextMessageWriter.cs | 6 ++--- .../PartwiseStreamMessageReader.cs | 3 +-- .../PartwiseStreamMessageWriter.cs | 3 +-- .../JsonRpcHttpMessageDirectHandler.cs | 3 +-- UnitTestProject1/Helpers/TestLogger.cs | 6 ++--- 15 files changed, 43 insertions(+), 36 deletions(-) diff --git a/JsonRpc.AspNetCore/AspNetCoreFeatureCollection.cs b/JsonRpc.AspNetCore/AspNetCoreFeatureCollection.cs index 137804f..9b82882 100644 --- a/JsonRpc.AspNetCore/AspNetCoreFeatureCollection.cs +++ b/JsonRpc.AspNetCore/AspNetCoreFeatureCollection.cs @@ -13,9 +13,8 @@ internal class AspNetCoreFeatureCollection : IFeatureCollection public AspNetCoreFeatureCollection(IFeatureCollection baseCollection, HttpContext context) { - if (context == null) throw new ArgumentNullException(nameof(context)); BaseCollection = baseCollection; - Context = context; + Context = context ?? throw new ArgumentNullException(nameof(context)); } public IFeatureCollection BaseCollection { get; } diff --git a/JsonRpc.AspNetCore/JsonRpcBuilder.cs b/JsonRpc.AspNetCore/JsonRpcBuilder.cs index ceee755..844f559 100644 --- a/JsonRpc.AspNetCore/JsonRpcBuilder.cs +++ b/JsonRpc.AspNetCore/JsonRpcBuilder.cs @@ -46,8 +46,7 @@ internal class JsonRpcBuilder : IJsonRpcBuilder public JsonRpcBuilder(JsonRpcOptions options, IServiceCollection serviceCollection) { if (options == null) throw new ArgumentNullException(nameof(options)); - if (serviceCollection == null) throw new ArgumentNullException(nameof(serviceCollection)); - this.serviceCollection = serviceCollection; + this.serviceCollection = serviceCollection ?? throw new ArgumentNullException(nameof(serviceCollection)); injectServices = options.InjectServiceTypes; serviceHostBuilder = new JsonRpcServiceHostBuilder { diff --git a/JsonRpc.Commons/Client/Exceptions.cs b/JsonRpc.Commons/Client/Exceptions.cs index 25671cd..194863b 100644 --- a/JsonRpc.Commons/Client/Exceptions.cs +++ b/JsonRpc.Commons/Client/Exceptions.cs @@ -17,6 +17,11 @@ namespace JsonRpc.Client #endif public class JsonRpcClientException : Exception { + public JsonRpcClientException() + : this(null, null) + { + } + public JsonRpcClientException(string message) : this(message, null) { @@ -43,6 +48,16 @@ protected JsonRpcClientException(SerializationInfo info, StreamingContext contex #endif public class JsonRpcContractException : JsonRpcClientException { + public JsonRpcContractException() + : this(null, null, null) + { + } + + public JsonRpcContractException(string message) + : this(message, null, null) + { + } + public JsonRpcContractException(string message, Exception innerException) : this(message, null, innerException) { @@ -91,6 +106,16 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont #endif public class JsonRpcRemoteException : JsonRpcClientException { + public JsonRpcRemoteException() + : this(null, null, null) + { + } + + public JsonRpcRemoteException(string message) + : this(message, null, null) + { + } + public JsonRpcRemoteException(string message, Exception innerException) : this(message, null, innerException) { diff --git a/JsonRpc.Commons/Client/JsonRpcClient.cs b/JsonRpc.Commons/Client/JsonRpcClient.cs index cf88755..47dd2d8 100644 --- a/JsonRpc.Commons/Client/JsonRpcClient.cs +++ b/JsonRpc.Commons/Client/JsonRpcClient.cs @@ -28,8 +28,7 @@ public class JsonRpcClient /// Handler used to transmit the messages. public JsonRpcClient(IJsonRpcClientHandler handler) { - if (handler == null) throw new ArgumentNullException(nameof(handler)); - Handler = handler; + Handler = handler ?? throw new ArgumentNullException(nameof(handler)); requestIdPrefix = RuntimeHelpers.GetHashCode(this) + "#"; } diff --git a/JsonRpc.Commons/Contracts/IJsonValueConverter.cs b/JsonRpc.Commons/Contracts/IJsonValueConverter.cs index fabdd3b..87d6411 100644 --- a/JsonRpc.Commons/Contracts/IJsonValueConverter.cs +++ b/JsonRpc.Commons/Contracts/IJsonValueConverter.cs @@ -37,8 +37,7 @@ public JsonValueConverter() : this(defaultSerializer) public JsonValueConverter(JsonSerializer serializer) { - if (serializer == null) throw new ArgumentNullException(nameof(serializer)); - this.serializer = serializer; + this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); } /// diff --git a/JsonRpc.Commons/Messages/MessageEventArgs.cs b/JsonRpc.Commons/Messages/MessageEventArgs.cs index a09e1fb..5a4a0cc 100644 --- a/JsonRpc.Commons/Messages/MessageEventArgs.cs +++ b/JsonRpc.Commons/Messages/MessageEventArgs.cs @@ -14,8 +14,7 @@ public class MessageEventArgs : EventArgs public MessageEventArgs(Message message) { - if (message == null) throw new ArgumentNullException(nameof(message)); - Message = message; + Message = message ?? throw new ArgumentNullException(nameof(message)); } } } diff --git a/JsonRpc.Commons/Server/JsonRpcServerHandler.cs b/JsonRpc.Commons/Server/JsonRpcServerHandler.cs index a14f269..e412533 100644 --- a/JsonRpc.Commons/Server/JsonRpcServerHandler.cs +++ b/JsonRpc.Commons/Server/JsonRpcServerHandler.cs @@ -12,8 +12,7 @@ public abstract class JsonRpcServerHandler public JsonRpcServerHandler(IJsonRpcServiceHost serviceHost) { - if (serviceHost == null) throw new ArgumentNullException(nameof(serviceHost)); - ServiceHost = serviceHost; + ServiceHost = serviceHost ?? throw new ArgumentNullException(nameof(serviceHost)); } /// diff --git a/JsonRpc.Commons/Server/JsonRpcServiceHost.cs b/JsonRpc.Commons/Server/JsonRpcServiceHost.cs index fba3a17..d068613 100644 --- a/JsonRpc.Commons/Server/JsonRpcServiceHost.cs +++ b/JsonRpc.Commons/Server/JsonRpcServiceHost.cs @@ -17,8 +17,7 @@ internal class JsonRpcServiceHost : IJsonRpcServiceHost internal JsonRpcServiceHost(JsonRpcServerContract contract) { - if (contract == null) throw new ArgumentNullException(nameof(contract)); - Contract = contract; + Contract = contract ?? throw new ArgumentNullException(nameof(contract)); } internal JsonRpcServerContract Contract { get; } diff --git a/JsonRpc.Commons/Server/RequestContext.cs b/JsonRpc.Commons/Server/RequestContext.cs index 1531d31..8757f51 100644 --- a/JsonRpc.Commons/Server/RequestContext.cs +++ b/JsonRpc.Commons/Server/RequestContext.cs @@ -12,11 +12,9 @@ public class RequestContext public RequestContext(IJsonRpcServiceHost serviceHost, IServiceFactory serviceFactory, IFeatureCollection features, RequestMessage request, CancellationToken cancellationToken) { - if (serviceHost == null) throw new ArgumentNullException(nameof(serviceHost)); - if (request == null) throw new ArgumentNullException(nameof(request)); - ServiceHost = serviceHost; + ServiceHost = serviceHost ?? throw new ArgumentNullException(nameof(serviceHost)); ServiceFactory = serviceFactory; - Request = request; + Request = request ?? throw new ArgumentNullException(nameof(request)); Features = features; if (!request.IsNotification) Response = new ResponseMessage(request.Id); diff --git a/JsonRpc.Streams/ByLineTextMessageReader.cs b/JsonRpc.Streams/ByLineTextMessageReader.cs index 24016de..8d4804a 100644 --- a/JsonRpc.Streams/ByLineTextMessageReader.cs +++ b/JsonRpc.Streams/ByLineTextMessageReader.cs @@ -35,9 +35,8 @@ public ByLineTextMessageReader(TextReader reader) : this(reader, "\n") /// Empty messages separated by will be ignored. public ByLineTextMessageReader(TextReader reader, string delimiter) { - if (reader == null) throw new ArgumentNullException(nameof(reader)); if (string.IsNullOrEmpty(delimiter)) throw new ArgumentException("delimiter cannot be null or empty.", nameof(delimiter)); - Reader = reader; + Reader = reader ?? throw new ArgumentNullException(nameof(reader)); Delimiter = delimiter; delimiterArray = delimiter.ToCharArray(); } @@ -58,9 +57,8 @@ public ByLineTextMessageReader(Stream stream) : this(stream, "\n") /// Empty messages separated by will be ignored. public ByLineTextMessageReader(Stream stream, string delimiter) { - if (stream == null) throw new ArgumentNullException(nameof(stream)); if (string.IsNullOrEmpty(delimiter)) throw new ArgumentException("delimiter cannot be null or empty.", nameof(delimiter)); - underlyingStream = stream; + underlyingStream = stream ?? throw new ArgumentNullException(nameof(stream)); Reader = new StreamReader(stream, Utility.UTF8NoBom, false, 1024, true); Delimiter = delimiter; delimiterArray = delimiter.ToCharArray(); diff --git a/JsonRpc.Streams/ByLineTextMessageWriter.cs b/JsonRpc.Streams/ByLineTextMessageWriter.cs index d1b5cce..18a879c 100644 --- a/JsonRpc.Streams/ByLineTextMessageWriter.cs +++ b/JsonRpc.Streams/ByLineTextMessageWriter.cs @@ -39,9 +39,8 @@ public ByLineTextMessageWriter(TextWriter writer) : this(writer, "\n") /// public ByLineTextMessageWriter(TextWriter writer, string delimiter) { - if (writer == null) throw new ArgumentNullException(nameof(writer)); if (string.IsNullOrEmpty(delimiter)) throw new ArgumentException("delimiter cannot be null or empty.", nameof(delimiter)); - Writer = writer; + Writer = writer ?? throw new ArgumentNullException(nameof(writer)); Delimiter = delimiter; } @@ -60,8 +59,7 @@ public ByLineTextMessageWriter(Stream stream) : this(stream, "\n") /// The delimiter between the messages. public ByLineTextMessageWriter(Stream stream, string delimiter) { - if (stream == null) throw new ArgumentNullException(nameof(stream)); - underlyingStream = stream; + underlyingStream = stream ?? throw new ArgumentNullException(nameof(stream)); Writer = new StreamWriter(stream); Delimiter = delimiter; } diff --git a/JsonRpc.Streams/PartwiseStreamMessageReader.cs b/JsonRpc.Streams/PartwiseStreamMessageReader.cs index cae81f4..4e5b676 100644 --- a/JsonRpc.Streams/PartwiseStreamMessageReader.cs +++ b/JsonRpc.Streams/PartwiseStreamMessageReader.cs @@ -30,8 +30,7 @@ public class PartwiseStreamMessageReader : QueuedMessageReader /// The stream to read messages from. public PartwiseStreamMessageReader(Stream stream) { - if (stream == null) throw new ArgumentNullException(nameof(stream)); - Stream = stream; + Stream = stream ?? throw new ArgumentNullException(nameof(stream)); } /// diff --git a/JsonRpc.Streams/PartwiseStreamMessageWriter.cs b/JsonRpc.Streams/PartwiseStreamMessageWriter.cs index e9766f7..8451c8f 100644 --- a/JsonRpc.Streams/PartwiseStreamMessageWriter.cs +++ b/JsonRpc.Streams/PartwiseStreamMessageWriter.cs @@ -24,8 +24,7 @@ public class PartwiseStreamMessageWriter : MessageWriter /// The stream to write messages to. public PartwiseStreamMessageWriter(Stream stream) { - if (stream == null) throw new ArgumentNullException(nameof(stream)); - Stream = stream; + Stream = stream ?? throw new ArgumentNullException(nameof(stream)); } /// diff --git a/UnitTestProject1/Helpers/JsonRpcHttpMessageDirectHandler.cs b/UnitTestProject1/Helpers/JsonRpcHttpMessageDirectHandler.cs index f71c53f..808b148 100644 --- a/UnitTestProject1/Helpers/JsonRpcHttpMessageDirectHandler.cs +++ b/UnitTestProject1/Helpers/JsonRpcHttpMessageDirectHandler.cs @@ -15,8 +15,7 @@ public class JsonRpcHttpMessageDirectHandler : HttpMessageHandler public JsonRpcHttpMessageDirectHandler(IJsonRpcServiceHost serviceHost) { - if (serviceHost == null) throw new ArgumentNullException(nameof(serviceHost)); - ServiceHost = serviceHost; + ServiceHost = serviceHost ?? throw new ArgumentNullException(nameof(serviceHost)); } public IJsonRpcServiceHost ServiceHost { get; } diff --git a/UnitTestProject1/Helpers/TestLogger.cs b/UnitTestProject1/Helpers/TestLogger.cs index 583a68d..32ca5e2 100644 --- a/UnitTestProject1/Helpers/TestLogger.cs +++ b/UnitTestProject1/Helpers/TestLogger.cs @@ -9,8 +9,7 @@ public class TestLoggerProvider : ILoggerProvider public TestLoggerProvider(ITestOutputHelper outputHelper) { - if (outputHelper == null) throw new ArgumentNullException(nameof(outputHelper)); - OutputHelper = outputHelper; + OutputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper)); } public ITestOutputHelper OutputHelper { get; } @@ -33,8 +32,7 @@ public class TestLogger : ILogger public TestLogger(ITestOutputHelper outputHelper, string name) { - if (outputHelper == null) throw new ArgumentNullException(nameof(outputHelper)); - OutputHelper = outputHelper; + OutputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper)); Name = name; }