Skip to content

Commit

Permalink
Merge pull request #160 from nenoNaninu/fix_nrt
Browse files Browse the repository at this point in the history
Fix nullable reference type annotations
  • Loading branch information
nenoNaninu authored Nov 27, 2023
2 parents 70c2505 + a29c7fc commit 43ac188
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TypedSignalR.Client.CodeAnalysis;

Expand All @@ -24,6 +23,7 @@ public string TransformText()
// </auto-generated>
#nullable enable
#pragma warning disable CS1591
#pragma warning disable CS8767
namespace TypedSignalR.Client
{
internal static partial class HubConnectionExtensions
Expand Down Expand Up @@ -67,6 +67,7 @@ private sealed class BinderFor_{{receiverType.CollisionFreeName}} : IReceiverBin
}
}
}
#pragma warning restore CS8767
#pragma warning restore CS1591
""");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public string TransformText()
// </auto-generated>
#nullable enable
#pragma warning disable CS1591
#pragma warning disable CS8767
namespace TypedSignalR.Client
{
internal static partial class HubConnectionExtensions
Expand Down Expand Up @@ -80,6 +81,7 @@ private sealed class HubInvokerFactoryFor_{{hubType.CollisionFreeName}} : IHubIn
}
}
}
#pragma warning restore CS8767
#pragma warning restore CS1591
""");

Expand Down
15 changes: 8 additions & 7 deletions src/TypedSignalR.Client/Templates/MethodMetadataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static string CreateArgumentsString(this MethodMetadata methodMetadata)

var sb = new StringBuilder();

sb.Append("new object[] { ");
sb.Append("new object?[] { ");
sb.Append(methodMetadata.Parameters[0].Name);

for (int i = 1; i < methodMetadata.Parameters.Count; i++)
Expand All @@ -63,7 +63,8 @@ public static string CreateArgumentsString(this MethodMetadata methodMetadata)
public static string CreateArgumentsStringExceptCancellationToken(this MethodMetadata methodMetadata, SpecialSymbols specialSymbols)
{
var parameters = methodMetadata.Parameters
.Where(x => !SymbolEqualityComparer.Default.Equals(x.Type, specialSymbols.CancellationTokenSymbol)).ToArray();
.Where(x => !SymbolEqualityComparer.Default.Equals(x.Type, specialSymbols.CancellationTokenSymbol))
.ToArray();

if (parameters.Length == 0)
{
Expand All @@ -72,7 +73,7 @@ public static string CreateArgumentsStringExceptCancellationToken(this MethodMet

var sb = new StringBuilder();

sb.Append("new object[] { ");
sb.Append("new object?[] { ");
sb.Append(parameters[0].Name);

for (int i = 1; i < parameters.Length; i++)
Expand Down Expand Up @@ -183,8 +184,8 @@ public static string CreateMethodString(this MethodMetadata methodMetadata, Spec
HubMethodType.ServerStreamingAsAsyncEnumerable => CreateServerStreamingMethodAsAsyncEnumerableString(methodMetadata, specialSymbols),
HubMethodType.ServerStreamingAsTaskAsyncEnumerable => CreateServerStreamingMethodAsTaskAsyncEnumerableString(methodMetadata, specialSymbols),
HubMethodType.ServerStreamingAsChannel => CreateServerStreamingMethodAsChannelString(methodMetadata, specialSymbols),
HubMethodType.ClientStreamingAsAsyncEnumerable => CreateClientStreamingMethodAsAsyncEnumerableString(methodMetadata, specialSymbols),
HubMethodType.ClientStreamingAsChannel => CreateClientStreamingMethodAsChannelString(methodMetadata, specialSymbols),
HubMethodType.ClientStreamingAsAsyncEnumerable => CreateClientStreamingMethodAsAsyncEnumerableString(methodMetadata),
HubMethodType.ClientStreamingAsChannel => CreateClientStreamingMethodAsChannelString(methodMetadata),
_ => string.Empty
};
}
Expand Down Expand Up @@ -294,7 +295,7 @@ private static string CreateServerStreamingMethodAsChannelString(MethodMetadata
""";
}

private static string CreateClientStreamingMethodAsAsyncEnumerableString(MethodMetadata method, SpecialSymbols specialSymbols)
private static string CreateClientStreamingMethodAsAsyncEnumerableString(MethodMetadata method)
{
return $$"""
public {{method.ReturnType}} {{method.MethodName}}({{method.CreateParametersString()}})
Expand All @@ -304,7 +305,7 @@ private static string CreateClientStreamingMethodAsAsyncEnumerableString(MethodM
""";
}

private static string CreateClientStreamingMethodAsChannelString(MethodMetadata method, SpecialSymbols specialSymbols)
private static string CreateClientStreamingMethodAsChannelString(MethodMetadata method)
{
return $$"""
Expand Down

0 comments on commit 43ac188

Please sign in to comment.