Skip to content

Commit

Permalink
Merge pull request #198 from nenoNaninu/refactor_20240403
Browse files Browse the repository at this point in the history
refactor
  • Loading branch information
nenoNaninu authored Apr 3, 2024
2 parents 4c62300 + 99fddc5 commit 1464152
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/TypedSignalR.Client/CodeAnalysis/ParameterMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public readonly record struct ParameterMetadata
public readonly string TypeName;

public ITypeSymbol Type => ParameterSymbol.Type;
public string FullyQualifiedTypeName => ParameterSymbol.Type.ToDisplayString(SymbolDisplayFormatRule.FullyQualifiedFormat);

public ParameterMetadata(IParameterSymbol parameterSymbol)
{
Expand Down
6 changes: 3 additions & 3 deletions src/TypedSignalR.Client/CodeAnalysis/TypeMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class TypeMetadata : ITypeSymbolHolder
public IReadOnlyList<MethodMetadata> Methods { get; }

public string InterfaceName { get; }
public string InterfaceFullName { get; }
public string FullyQualifiedInterfaceName { get; }
public string CollisionFreeName { get; }

public TypeMetadata(ITypeSymbol typeSymbol)
Expand All @@ -21,8 +21,8 @@ public TypeMetadata(ITypeSymbol typeSymbol)
Methods = GetMethods(typeSymbol);

InterfaceName = typeSymbol.Name;
InterfaceFullName = typeSymbol.ToDisplayString(SymbolDisplayFormatRule.FullyQualifiedFormat);
CollisionFreeName = InterfaceFullName.Replace('.', '_').Replace(':', '_');
FullyQualifiedInterfaceName = typeSymbol.ToDisplayString(SymbolDisplayFormatRule.FullyQualifiedFormat);
CollisionFreeName = FullyQualifiedInterfaceName.Replace('.', '_').Replace(':', '_');
}

private static IReadOnlyList<MethodMetadata> GetMethods(ITypeSymbol typeSymbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ internal static partial class HubConnectionExtensions
foreach (var receiverType in _receiverTypes)
{
sb.AppendLine($$"""
private sealed class BinderFor_{{receiverType.CollisionFreeName}} : IReceiverBinder<{{receiverType.InterfaceFullName}}>
private sealed class BinderFor_{{receiverType.CollisionFreeName}} : IReceiverBinder<{{receiverType.FullyQualifiedInterfaceName}}>
{
public global::System.IDisposable Bind(global::Microsoft.AspNetCore.SignalR.Client.HubConnection connection, {{receiverType.InterfaceFullName}} receiver)
public global::System.IDisposable Bind(global::Microsoft.AspNetCore.SignalR.Client.HubConnection connection, {{receiverType.FullyQualifiedInterfaceName}} receiver)
{
var compositeDisposable = new CompositeDisposable({{receiverType.Methods.Count}});

Expand All @@ -58,7 +58,7 @@ private sealed class BinderFor_{{receiverType.CollisionFreeName}} : IReceiverBin
foreach (var receiverType in _receiverTypes)
{
sb.AppendLine($$"""
binders.Add(typeof({{receiverType.InterfaceFullName}}), new BinderFor_{{receiverType.CollisionFreeName}}());
binders.Add(typeof({{receiverType.FullyQualifiedInterfaceName}}), new BinderFor_{{receiverType.CollisionFreeName}}());
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static partial class HubConnectionExtensions
foreach (var hubType in _hubTypes)
{
sb.AppendLine($$"""
private sealed class HubInvokerFor_{{hubType.CollisionFreeName}} : {{hubType.InterfaceFullName}}, IHubInvoker
private sealed class HubInvokerFor_{{hubType.CollisionFreeName}} : {{hubType.FullyQualifiedInterfaceName}}, IHubInvoker
{
private readonly global::Microsoft.AspNetCore.SignalR.Client.HubConnection _connection;
private readonly global::System.Threading.CancellationToken _cancellationToken;
Expand All @@ -50,9 +50,9 @@ private sealed class HubInvokerFor_{{hubType.CollisionFreeName}} : {{hubType.Int
{{CreateMethodsString(hubType)}}
}

private sealed class HubInvokerFactoryFor_{{hubType.CollisionFreeName}} : IHubInvokerFactory<{{hubType.InterfaceFullName}}>
private sealed class HubInvokerFactoryFor_{{hubType.CollisionFreeName}} : IHubInvokerFactory<{{hubType.FullyQualifiedInterfaceName}}>
{
public {{hubType.InterfaceFullName}} CreateHubInvoker(global::Microsoft.AspNetCore.SignalR.Client.HubConnection connection, global::System.Threading.CancellationToken cancellationToken)
public {{hubType.FullyQualifiedInterfaceName}} CreateHubInvoker(global::Microsoft.AspNetCore.SignalR.Client.HubConnection connection, global::System.Threading.CancellationToken cancellationToken)
{
return new HubInvokerFor_{{hubType.CollisionFreeName}}(connection, cancellationToken);
}
Expand All @@ -72,7 +72,7 @@ private sealed class HubInvokerFactoryFor_{{hubType.CollisionFreeName}} : IHubIn
foreach (var hubType in _hubTypes)
{
sb.AppendLine($$"""
factories.Add(typeof({{hubType.InterfaceFullName}}), new HubInvokerFactoryFor_{{hubType.CollisionFreeName}}());
factories.Add(typeof({{hubType.FullyQualifiedInterfaceName}}), new HubInvokerFactoryFor_{{hubType.CollisionFreeName}}());
""");
}

Expand Down
6 changes: 3 additions & 3 deletions src/TypedSignalR.Client/Templates/MethodMetadataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ public static string CreateParameterTypeArrayString(this MethodMetadata methodMe

if (methodMetadata.Parameters.Count == 1)
{
return $"new[] {{ typeof({methodMetadata.Parameters[0].Type.ToDisplayString(SymbolDisplayFormatRule.FullyQualifiedFormat)}) }}";
return $"new[] {{ typeof({methodMetadata.Parameters[0].FullyQualifiedTypeName}) }}";
}

var sb = new StringBuilder();

sb.Append("new[] { ");
sb.Append($"typeof({methodMetadata.Parameters[0].Type.ToDisplayString(SymbolDisplayFormatRule.FullyQualifiedFormat)})");
sb.Append($"typeof({methodMetadata.Parameters[0].FullyQualifiedTypeName})");

for (int i = 1; i < methodMetadata.Parameters.Count; i++)
{
sb.Append($", typeof({methodMetadata.Parameters[i].Type.ToDisplayString(SymbolDisplayFormatRule.FullyQualifiedFormat)})");
sb.Append($", typeof({methodMetadata.Parameters[i].FullyQualifiedTypeName})");
}

sb.Append(" }");
Expand Down

0 comments on commit 1464152

Please sign in to comment.