Skip to content

Commit

Permalink
Merge pull request #92 from nenoNaninu/roslyn_v4.3.1
Browse files Browse the repository at this point in the history
Roslyn v4.3.1
  • Loading branch information
nenoNaninu authored Feb 7, 2023
2 parents 0142aa3 + a7fe5d8 commit c163f00
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 42 deletions.
19 changes: 10 additions & 9 deletions src/TypedSignalR.Client/CodeAnalysis/SpecialSymbols.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

namespace TypedSignalR.Client.CodeAnalysis;
Expand All @@ -9,27 +10,27 @@ public class SpecialSymbols
public readonly INamedTypeSymbol CancellationTokenSymbol;
public readonly INamedTypeSymbol AsyncEnumerableSymbol;
public readonly INamedTypeSymbol ChannelReaderSymbol;
public readonly INamedTypeSymbol HubConnectionObserverSymbol;
public readonly IMethodSymbol CreateHubProxyMethodSymbol;
public readonly IMethodSymbol RegisterMethodSymbol;
public readonly ImmutableArray<INamedTypeSymbol> HubConnectionObserverSymbols;
public readonly ImmutableArray<IMethodSymbol> CreateHubProxyMethodSymbols;
public readonly ImmutableArray<IMethodSymbol> RegisterMethodSymbols;

public SpecialSymbols(
INamedTypeSymbol taskSymbol,
INamedTypeSymbol genericTaskSymbol,
INamedTypeSymbol cancellationTokenSymbol,
INamedTypeSymbol asyncEnumerableSymbol,
INamedTypeSymbol channelReaderSymbol,
INamedTypeSymbol hubConnectionObserverSymbol,
IMethodSymbol createHubProxyMethodSymbol,
IMethodSymbol registerMethodSymbol)
ImmutableArray<INamedTypeSymbol> hubConnectionObserverSymbols,
ImmutableArray<IMethodSymbol> createHubProxyMethodSymbols,
ImmutableArray<IMethodSymbol> registerMethodSymbols)
{
TaskSymbol = taskSymbol;
GenericTaskSymbol = genericTaskSymbol;
CancellationTokenSymbol = cancellationTokenSymbol;
AsyncEnumerableSymbol = asyncEnumerableSymbol;
ChannelReaderSymbol = channelReaderSymbol;
HubConnectionObserverSymbol = hubConnectionObserverSymbol;
CreateHubProxyMethodSymbol = createHubProxyMethodSymbol;
RegisterMethodSymbol = registerMethodSymbol;
HubConnectionObserverSymbols = hubConnectionObserverSymbols;
CreateHubProxyMethodSymbols = createHubProxyMethodSymbols;
RegisterMethodSymbols = registerMethodSymbols;
}
}
65 changes: 33 additions & 32 deletions src/TypedSignalR.Client/SourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,12 @@ private static ValidatedSourceSymbol ValidateCreateHubProxyMethodSymbol((SourceS
return default;
}

if (SymbolEqualityComparer.Default.Equals(extensionMethodSymbol, specialSymbols.CreateHubProxyMethodSymbol))
foreach (var createHubProxyMethodSymbol in specialSymbols.CreateHubProxyMethodSymbols)
{
return new ValidatedSourceSymbol(methodSymbol, location);
if (SymbolEqualityComparer.Default.Equals(extensionMethodSymbol, createHubProxyMethodSymbol))
{
return new ValidatedSourceSymbol(methodSymbol, location);
}
}

return default;
Expand Down Expand Up @@ -159,9 +162,12 @@ private static ValidatedSourceSymbol ValidateRegisterMethodSymbol((SourceSymbol,
return default;
}

if (SymbolEqualityComparer.Default.Equals(extensionMethodSymbol, specialSymbols.RegisterMethodSymbol))
foreach (var registerMethodSymbol in specialSymbols.RegisterMethodSymbols)
{
return new ValidatedSourceSymbol(methodSymbol, location);
if (SymbolEqualityComparer.Default.Equals(extensionMethodSymbol, registerMethodSymbol))
{
return new ValidatedSourceSymbol(methodSymbol, location);
}
}

return default;
Expand Down Expand Up @@ -233,41 +239,33 @@ private static SpecialSymbols GetSpecialSymbols(Compilation compilation)
var cancellationTokenSymbol = compilation.GetTypeByMetadataName("System.Threading.CancellationToken");
var asyncEnumerableSymbol = compilation.GetTypeByMetadataName("System.Collections.Generic.IAsyncEnumerable`1");
var channelReaderSymbol = compilation.GetTypeByMetadataName("System.Threading.Channels.ChannelReader`1");
var hubConnectionObserverSymbol = compilation.GetTypeByMetadataName("TypedSignalR.Client.IHubConnectionObserver");
var memberSymbols = compilation.GetTypeByMetadataName("TypedSignalR.Client.HubConnectionExtensions")!.GetMembers();
var hubConnectionObserverSymbol = compilation.GetTypesByMetadataName("TypedSignalR.Client.IHubConnectionObserver");
var hubConnectionExtensions = compilation.GetTypesByMetadataName("TypedSignalR.Client.HubConnectionExtensions");

IMethodSymbol? createHubProxyMethodSymbol = null;
IMethodSymbol? registerMethodSymbol = null;
ImmutableArray<IMethodSymbol> createHubProxyMethodSymbol = ImmutableArray<IMethodSymbol>.Empty;
ImmutableArray<IMethodSymbol> registerMethodSymbol = ImmutableArray<IMethodSymbol>.Empty;

foreach (var memberSymbol in memberSymbols)
foreach (var hubConnectionExtension in hubConnectionExtensions)
{
if (memberSymbol is not IMethodSymbol methodSymbol)
foreach (var memberSymbol in hubConnectionExtension.GetMembers())
{
continue;
}
if (memberSymbol is not IMethodSymbol methodSymbol)
{
continue;
}

if (methodSymbol.Name is "CreateHubProxy")
{
if (methodSymbol.MethodKind is MethodKind.Ordinary)
if (methodSymbol.MethodKind is not MethodKind.Ordinary)
{
createHubProxyMethodSymbol = methodSymbol;
continue;
}

if (registerMethodSymbol is not null)
{
break;
}
if (methodSymbol.Name is "CreateHubProxy")
{
createHubProxyMethodSymbol = createHubProxyMethodSymbol.Add(methodSymbol);
}
}
else if (methodSymbol.Name is "Register")
{
if (methodSymbol.MethodKind is MethodKind.Ordinary)
else if (methodSymbol.Name is "Register")
{
registerMethodSymbol = methodSymbol;

if (createHubProxyMethodSymbol is not null)
{
break;
}
registerMethodSymbol = registerMethodSymbol.Add(methodSymbol);
}
}
}
Expand Down Expand Up @@ -323,9 +321,12 @@ private static IReadOnlyList<TypeMetadata> ExtractReceiverTypesFromRegisterMetho

ITypeSymbol receiverTypeSymbol = methodSymbol.TypeArguments[0];

if (SymbolEqualityComparer.Default.Equals(receiverTypeSymbol, specialSymbols.HubConnectionObserverSymbol))
foreach (var hubConnectionObserverSymbol in specialSymbols.HubConnectionObserverSymbols)
{
continue;
if (SymbolEqualityComparer.Default.Equals(receiverTypeSymbol, hubConnectionObserverSymbol))
{
continue;
}
}

var isValid = TypeValidator.ValidateReceiverTypeRule(context, receiverTypeSymbol, specialSymbols, location);
Expand Down
2 changes: 1 addition & 1 deletion src/TypedSignalR.Client/TypedSignalR.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.1" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit c163f00

Please sign in to comment.