cleanup: Fix numerous build warnings in DataStreamSuite
Nearly all warnings were due to nullability issues, since the concept of nullable reference types did not exist when the DataStream code was originally written. * PubSubClientMessage - Normalize indentation/whitespace - Fix some typos - Address nullability issues to fix build warnings - Modernize code * Compression related files - ZipEntry - ZipFile - ZipInputStream - TarHeader * RemoteMessage - make 'message' nullable to resolve warnings elsewhere (in calling code) * PubSubSingleTagStateEvent.cs * PubSubMessageReactor * PubSubState * SystemHeartbeatPublisher * SystemStatsPublisher * SingleTagData * ManagedTCPMessageHub * PubsubDeserializationController * PublisherCore * InflaterHuffmanTree * AsyncTCPConnection_APM * ThreadSafeQueue * ManagedSubscriber * SubscriberCore * PubSubServerManagedTCPConnection * AsyncTCPConnection_APM * SuperMapStream * MapStream * TradeBarsStream
This commit is contained in:
1 parent
5426ba0aa7
commit
60a52b3922
34 files changed
+839
-817
No files matched your search
@@ -5,14 +5,15 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace mbts.utils {
|
||||
static class ExceptionAssert {
|
||||
public static class ExceptionAssert {
|
||||
public static T of_type<T>(object obj, string name = null) =>
|
||||
obj is T ? (T)obj : throw new ArgumentException($"Expected {typeof(T)}, actually {(obj?.GetType()?.ToString() ?? "null")}.", name);
|
||||
|
||||
#nullable enable
|
||||
public static T not_null<T>([NotNull]T? obj, string? name = null) {
|
||||
public static T not_null<T>([NotNull] T? obj, string? name = null) {
|
||||
if (obj is null) {
|
||||
throw new ArgumentNullException(name ?? nameof(obj));
|
||||
}
|
||||
@@ -25,12 +26,32 @@ namespace mbts.utils {
|
||||
if (index < 0) throw ExceptionBuilder.IndexOutOfRange.lt_zero();
|
||||
}
|
||||
|
||||
public static ArgumentCastor<T> Cast<T>(T argument) =>
|
||||
new(argument);
|
||||
|
||||
public readonly struct ArgumentCastor<T> {
|
||||
public readonly T Argument;
|
||||
|
||||
public ArgumentCastor(T argument) =>
|
||||
Argument = argument;
|
||||
|
||||
public TResult To<TResult>() =>
|
||||
ExceptionAssert.Argument.OfType<T, TResult>(Argument);
|
||||
}
|
||||
|
||||
public static class Argument {
|
||||
public static T Is<T>(object argument, string name) {
|
||||
public static T Is<T>(object argument, [CallerArgumentExpression(nameof(argument))]string name = "") {
|
||||
if (argument is T t) return t;
|
||||
else throw new ArgumentException($"Must be of type {typeof(T)}.", name);
|
||||
}
|
||||
|
||||
public static TResult OfType<T, TResult>(T argument, [CallerArgumentExpression(nameof(argument))]string name = "") {
|
||||
if (argument is TResult r) {
|
||||
return r;
|
||||
}
|
||||
throw new ArgumentException($"Must be of type {typeof(T)}.", name);
|
||||
}
|
||||
|
||||
public static void IsNot<T>(object argument, string name) {
|
||||
if (argument is T)
|
||||
throw new ArgumentException($"Must not be of type {typeof(T)}.", name);
|
||||
@@ -41,6 +62,11 @@ namespace mbts.utils {
|
||||
throw ExceptionBuilder.Argument.must_be(condition_description, name);
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
public static T[] NotNullOrEmpty<T>([NotNull]T[]? argument, [CallerArgumentExpression(nameof(argument))] string name = "") =>
|
||||
argument?.Length > 0 ? argument : throw new ArgumentException("Must not be null or empty.", name);
|
||||
#nullable disable
|
||||
|
||||
public static void NotNull(object argument, string name) {
|
||||
if (argument == null)
|
||||
throw new ArgumentNullException(name);
|
||||
|
||||
Reference in new issue
Block a user