Fix up compiler warnings
This commit is contained in:
Родитель
4811a55939
Коммит
8ffa6684b4
|
@ -34,6 +34,9 @@ public class BadRpcHeaderException : RemoteRpcException
|
|||
/// </summary>
|
||||
/// <param name="info">Serialization info.</param>
|
||||
/// <param name="context">Streaming context.</param>
|
||||
#if NET8_0_OR_GREATER
|
||||
[Obsolete]
|
||||
#endif
|
||||
protected BadRpcHeaderException(
|
||||
System.Runtime.Serialization.SerializationInfo info,
|
||||
System.Runtime.Serialization.StreamingContext context)
|
||||
|
|
|
@ -42,6 +42,9 @@ public class ConnectionLostException : RemoteRpcException
|
|||
/// </summary>
|
||||
/// <param name="info">Serialization info.</param>
|
||||
/// <param name="context">Streaming context.</param>
|
||||
#if NET8_0_OR_GREATER
|
||||
[Obsolete]
|
||||
#endif
|
||||
protected ConnectionLostException(
|
||||
System.Runtime.Serialization.SerializationInfo info,
|
||||
System.Runtime.Serialization.StreamingContext context)
|
||||
|
|
|
@ -64,6 +64,9 @@ public class RemoteInvocationException : RemoteRpcException
|
|||
/// </summary>
|
||||
/// <param name="info">Serialization info.</param>
|
||||
/// <param name="context">Streaming context.</param>
|
||||
#if NET8_0_OR_GREATER
|
||||
[Obsolete]
|
||||
#endif
|
||||
protected RemoteInvocationException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
|
|
|
@ -41,6 +41,9 @@ public class RemoteMethodNotFoundException : RemoteRpcException
|
|||
/// </summary>
|
||||
/// <param name="info">Serialization info.</param>
|
||||
/// <param name="context">Streaming context.</param>
|
||||
#if NET8_0_OR_GREATER
|
||||
[Obsolete]
|
||||
#endif
|
||||
protected RemoteMethodNotFoundException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
|
@ -67,6 +70,9 @@ public class RemoteMethodNotFoundException : RemoteRpcException
|
|||
public new object? DeserializedErrorData => base.DeserializedErrorData;
|
||||
|
||||
/// <inheritdoc/>
|
||||
#if NET8_0_OR_GREATER
|
||||
[Obsolete]
|
||||
#endif
|
||||
public override void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
base.GetObjectData(info, context);
|
||||
|
|
|
@ -37,6 +37,9 @@ public abstract class RemoteRpcException : Exception
|
|||
/// </summary>
|
||||
/// <param name="info">Serialization info.</param>
|
||||
/// <param name="context">Streaming context.</param>
|
||||
#if NET8_0_OR_GREATER
|
||||
[Obsolete]
|
||||
#endif
|
||||
protected RemoteRpcException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
|
@ -69,6 +72,9 @@ public abstract class RemoteRpcException : Exception
|
|||
public object? DeserializedErrorData { get; protected set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
#if NET8_0_OR_GREATER
|
||||
[Obsolete]
|
||||
#endif
|
||||
public override void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
base.GetObjectData(info, context);
|
||||
|
|
|
@ -31,6 +31,9 @@ public class RemoteSerializationException : RemoteRpcException
|
|||
/// </summary>
|
||||
/// <param name="serializationInfo">Serialization info.</param>
|
||||
/// <param name="streamingContext">Streaming context.</param>
|
||||
#if NET8_0_OR_GREATER
|
||||
[Obsolete]
|
||||
#endif
|
||||
protected RemoteSerializationException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext)
|
||||
: base(serializationInfo, streamingContext)
|
||||
{
|
||||
|
|
|
@ -52,6 +52,9 @@ public class RpcArgumentDeserializationException : RemoteRpcException
|
|||
/// </summary>
|
||||
/// <param name="info">Serialization info.</param>
|
||||
/// <param name="context">Serialization context.</param>
|
||||
#if NET8_0_OR_GREATER
|
||||
[Obsolete]
|
||||
#endif
|
||||
protected RpcArgumentDeserializationException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
|
@ -85,6 +88,9 @@ public class RpcArgumentDeserializationException : RemoteRpcException
|
|||
public Type? DeserializedType { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
#if NET8_0_OR_GREATER
|
||||
[Obsolete]
|
||||
#endif
|
||||
public override void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
base.GetObjectData(info, context);
|
||||
|
|
|
@ -43,6 +43,9 @@ public class UnrecognizedJsonRpcMessageException : RemoteRpcException
|
|||
/// </summary>
|
||||
/// <param name="info">Serialization info.</param>
|
||||
/// <param name="context">Streaming context.</param>
|
||||
#if NET8_0_OR_GREATER
|
||||
[Obsolete]
|
||||
#endif
|
||||
protected UnrecognizedJsonRpcMessageException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
|
|
|
@ -1288,7 +1288,10 @@ public class JsonMessageFormatter : FormatterBase, IJsonRpcAsyncMessageTextForma
|
|||
this.serializer = serializer;
|
||||
}
|
||||
|
||||
public object Convert(object value, Type type) => ((JToken)value).ToObject(type, this.serializer)!;
|
||||
#pragma warning disable CS8766 // This method may in fact return null, and no one cares.
|
||||
public object? Convert(object value, Type type)
|
||||
#pragma warning restore CS8766
|
||||
=> ((JToken)value).ToObject(type, this.serializer);
|
||||
|
||||
public object Convert(object value, TypeCode typeCode)
|
||||
{
|
||||
|
|
|
@ -2219,7 +2219,7 @@ public class JsonRpc : IDisposableObservable, IJsonRpcFormatterCallbacks, IJsonR
|
|||
|
||||
// Be sure to dispose the link to the local method token we created in case it is linked to our long-lived disposal token
|
||||
// and otherwise cause a memory leak.
|
||||
#if NETSTANDARD2_1_OR_GREATER
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
|
||||
await disconnectedRegistration.DisposeAsync().ConfigureAwait(false);
|
||||
#else
|
||||
disconnectedRegistration.Dispose();
|
||||
|
|
|
@ -239,7 +239,11 @@ public abstract class MessageHandlerBase : IJsonRpcMessageHandler, IDisposableOb
|
|||
{
|
||||
if (!this.disposalTokenSource.IsCancellationRequested)
|
||||
{
|
||||
#if NET8_0_OR_GREATER
|
||||
await this.disposalTokenSource.CancelAsync().ConfigureAwait(false);
|
||||
#else
|
||||
this.disposalTokenSource.Cancel();
|
||||
#endif
|
||||
|
||||
// Kick off disposal of reading and/or writing resources based on whether they're active right now or not.
|
||||
// If they're active, they'll take care of themselves when they finish since we signaled disposal.
|
||||
|
|
|
@ -405,7 +405,7 @@ public class MessagePackFormatter : FormatterBase, IJsonRpcMessageFormatter, IJs
|
|||
private static void ReadUnknownProperty(ref MessagePackReader reader, ref Dictionary<string, ReadOnlySequence<byte>>? topLevelProperties, ReadOnlySpan<byte> stringKey)
|
||||
{
|
||||
topLevelProperties ??= new Dictionary<string, ReadOnlySequence<byte>>(StringComparer.Ordinal);
|
||||
#if NETSTANDARD2_1_OR_GREATER
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
|
||||
string name = Encoding.UTF8.GetString(stringKey);
|
||||
#else
|
||||
string name = Encoding.UTF8.GetString(stringKey.ToArray());
|
||||
|
@ -660,7 +660,10 @@ public class MessagePackFormatter : FormatterBase, IJsonRpcMessageFormatter, IJs
|
|||
this.options = options;
|
||||
}
|
||||
|
||||
public object? Convert(object value, Type type) => ((RawMessagePack)value).Deserialize(type, this.options);
|
||||
#pragma warning disable CS8766 // This method may in fact return null, and no one cares.
|
||||
public object? Convert(object value, Type type)
|
||||
#pragma warning restore CS8766
|
||||
=> ((RawMessagePack)value).Deserialize(type, this.options);
|
||||
|
||||
public object Convert(object value, TypeCode typeCode)
|
||||
{
|
||||
|
|
|
@ -302,7 +302,7 @@ internal static class ProxyGeneration
|
|||
|
||||
Label positionalArgsLabel = il.DefineLabel();
|
||||
|
||||
ParameterInfo cancellationTokenParameter = methodParameters.FirstOrDefault(p => p.ParameterType == typeof(CancellationToken));
|
||||
ParameterInfo? cancellationTokenParameter = methodParameters.FirstOrDefault(p => p.ParameterType == typeof(CancellationToken));
|
||||
int argumentCountExcludingCancellationToken = methodParameters.Length - (cancellationTokenParameter is not null ? 1 : 0);
|
||||
VerifySupported(cancellationTokenParameter is null || cancellationTokenParameter.Position == methodParameters.Length - 1, Resources.CancellationTokenMustBeLastParameter, method);
|
||||
|
||||
|
@ -913,11 +913,11 @@ internal static class ProxyGeneration
|
|||
public bool Equals(GeneratedProxiesByInterfaceKey other)
|
||||
{
|
||||
return this.baseInterfaceType == other.baseInterfaceType &&
|
||||
!(this.implementedOptionalInterfaces is not null ^ other.implementedOptionalInterfaces is not null) &&
|
||||
(this.implementedOptionalInterfaces?.SequenceEqual(other.implementedOptionalInterfaces) ?? true);
|
||||
((this.implementedOptionalInterfaces is null && other.implementedOptionalInterfaces is null) ||
|
||||
(this.implementedOptionalInterfaces is not null && other.implementedOptionalInterfaces is not null && this.implementedOptionalInterfaces.SequenceEqual(other.implementedOptionalInterfaces)));
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is GeneratedProxiesByInterfaceKey other && this.Equals(other);
|
||||
}
|
||||
|
|
|
@ -88,7 +88,9 @@ internal static class ExceptionSerializationHelpers
|
|||
{
|
||||
Type exceptionType = exception.GetType();
|
||||
EnsureSerializableAttribute(exceptionType);
|
||||
#pragma warning disable SYSLIB0051 // Type or member is obsolete -- NOT so obsolete without the BinaryFormatter.
|
||||
exception.GetObjectData(info, Context);
|
||||
#pragma warning restore SYSLIB0051 // Type or member is obsolete
|
||||
info.AddValue(AssemblyNameKeyName, exception.GetType().Assembly.FullName);
|
||||
}
|
||||
|
||||
|
|
|
@ -322,11 +322,15 @@ public class MessageFormatterEnumerableTracker
|
|||
}
|
||||
}
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
#if NET8_0_OR_GREATER
|
||||
await this.cancellationTokenSource.CancelAsync().ConfigureAwait(false);
|
||||
#else
|
||||
this.cancellationTokenSource.Cancel();
|
||||
#endif
|
||||
this.readAheadElements?.Complete();
|
||||
return this.enumerator.DisposeAsync();
|
||||
await this.enumerator.DisposeAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task ReadAheadAsync()
|
||||
|
|
|
@ -530,7 +530,8 @@ internal class RpcTargetInfo : System.IAsyncDisposable
|
|||
// Only add methods that do not have equivalent signatures to what we already have.
|
||||
foreach (MethodSignature newMethod in item.Value)
|
||||
{
|
||||
if (!alreadyExists || !existingList.Any(e => e.Equals(newMethod)))
|
||||
// Null forgiveness operator in use due to: https://github.com/dotnet/roslyn/issues/73274
|
||||
if (!alreadyExists || !existingList!.Any(e => e.Equals(newMethod)))
|
||||
{
|
||||
var signatureAndTarget = new MethodSignatureAndTarget(newMethod, target, null);
|
||||
this.TraceLocalMethodAdded(rpcMethodName, signatureAndTarget);
|
||||
|
|
|
@ -15,7 +15,7 @@ internal static class TrackerHelpers<TInterface>
|
|||
/// <summary>
|
||||
/// Dictionary to record the calculation made in <see cref="FindInterfaceImplementedBy(Type)"/> to obtain the <typeparamref name="TInterface"/> type from a given <see cref="Type"/>.
|
||||
/// </summary>
|
||||
private static readonly Dictionary<Type, Type> TypeToImplementedInterfaceMap = new Dictionary<Type, Type>();
|
||||
private static readonly Dictionary<Type, Type?> TypeToImplementedInterfaceMap = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the generic type definition for whatever type parameter was given by <typeparamref name="TInterface" />.
|
||||
|
|
|
@ -104,7 +104,7 @@ public struct RequestId : IEquatable<RequestId>
|
|||
public override bool Equals(object? obj) => obj is RequestId other && this.Equals(other);
|
||||
|
||||
/// <inheritdoc/>
|
||||
#if NETSTANDARD2_1_OR_GREATER
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
|
||||
public override int GetHashCode() => this.Number?.GetHashCode() ?? this.String?.GetHashCode(StringComparison.Ordinal) ?? 0;
|
||||
#else
|
||||
public override int GetHashCode() => this.Number?.GetHashCode() ?? this.String?.GetHashCode() ?? 0;
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Description>A cross-platform .NETStandard library that implements the JSON-RPC wire protocol and can use System.IO.Stream, System.IO.Pipelines or WebSocket so you can use it with any transport.</Description>
|
||||
<PackageTags>visualstudio stream json rpc jsonrpc</PackageTags>
|
||||
<!-- We use the ISerializable APIs *without* the BinaryFormatter. Not as obsolete as the .NET SDK would have us believe. -->
|
||||
<NoWarn>$(NoWarn);SYSLIB0050</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Resources.resx" />
|
||||
|
|
|
@ -1104,16 +1104,15 @@ public class SystemTextJsonFormatter : FormatterBase, IJsonRpcMessageFormatter,
|
|||
this.serializerOptions = serializerOptions;
|
||||
}
|
||||
|
||||
#pragma warning disable CS8766 // This method may in fact return null, and no one cares.
|
||||
public object? Convert(object value, Type type)
|
||||
#pragma warning restore CS8766
|
||||
{
|
||||
var jsonValue = (JsonNode?)value;
|
||||
if (jsonValue is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var jsonValue = (JsonNode)value;
|
||||
|
||||
if (type == typeof(System.Collections.IDictionary))
|
||||
{
|
||||
// In this world, we may in fact be returning a null value based on a non-null value.
|
||||
return DeserializePrimitive(jsonValue);
|
||||
}
|
||||
|
||||
|
|
|
@ -82,14 +82,14 @@ public class WebSocketMessageHandler : MessageHandlerBase, IJsonRpcMessageBuffer
|
|||
/// <inheritdoc />
|
||||
protected override async ValueTask<JsonRpcMessage?> ReadCoreAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
#if NETSTANDARD2_1_OR_GREATER
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
|
||||
ValueWebSocketReceiveResult result;
|
||||
#else
|
||||
WebSocketReceiveResult result;
|
||||
#endif
|
||||
do
|
||||
{
|
||||
#if NETSTANDARD2_1_OR_GREATER
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
|
||||
Memory<byte> memory = this.contentSequenceBuilder.GetMemory(this.sizeHint);
|
||||
result = await this.WebSocket.ReceiveAsync(memory, cancellationToken).ConfigureAwait(false);
|
||||
this.contentSequenceBuilder.Advance(result.Count);
|
||||
|
@ -155,7 +155,7 @@ public class WebSocketMessageHandler : MessageHandlerBase, IJsonRpcMessageBuffer
|
|||
foreach (ReadOnlyMemory<byte> memory in contentSequence)
|
||||
{
|
||||
bool endOfMessage = bytesCopied + memory.Length == contentSequence.Length;
|
||||
#if NETSTANDARD2_1_OR_GREATER
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
|
||||
await this.WebSocket.SendAsync(memory, messageType, endOfMessage, cancellationToken).ConfigureAwait(false);
|
||||
#else
|
||||
if (MemoryMarshal.TryGetArray(memory, out ArraySegment<byte> segment))
|
||||
|
|
Загрузка…
Ссылка в новой задаче