Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TypeValidator #61

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions examples/Server/Hubs/InheritHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Server.Hubs;

public class InheritHub : Hub<IUnaryHubReceiver>, IInheritHub
public class InheritHub : Hub<IInheritHubReceiver>, IInheritHub
{
private readonly ILogger<InheritHub> _logger;

Expand All @@ -17,14 +17,17 @@ public Task<int> Add(int x, int y)
return Task.FromResult(x + y);
}

public Task<string> Cat(string x, string y)
public async Task<string> Cat(string x, string y)
{
return Task.FromResult(x + y);
var str = x + y;
await this.Clients.All.ReceiveMessage(str, str.Length);
return str;
}

public Task<UserDefinedType> Echo(UserDefinedType instance)
public async Task<UserDefinedType> Echo(UserDefinedType instance)
{
return Task.FromResult(instance);
await this.Clients.All.ReceiveCustomMessage(instance);
return instance;
}

public Task<string> Get()
Expand Down
19 changes: 18 additions & 1 deletion examples/Shared/IInheritHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,24 @@ public interface IInheritHub : IHubBase1, IHubBase2
Task<UserDefinedType> Echo(UserDefinedType instance);
}


public interface IReceiverBaseBase
{
Task ReceiveMessage(string message, int value);
}

public interface IReceiverBase1 : IReceiverBaseBase
{
Task ReceiveCustomMessage(UserDefinedType userDefined);
}

public interface IReceiverBase2 : IReceiverBaseBase
{
Task Notify();
}

[Receiver]
public interface IInheritHubReceiver
public interface IInheritHubReceiver : IReceiverBase1, IReceiverBase2
{
Task ReceiveMessage2(string message, int value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,32 @@ public static bool ValidateReceiverTypeRule(
return false;
}

bool isValid = ValidateReceiverTypeRuleCore(context, receiverTypeSymbol, specialSymbols, accessLocation);

var allInterfaces = receiverTypeSymbol.AllInterfaces;

if (allInterfaces.IsEmpty)
{
return isValid;
}

foreach (var typeSymbol in allInterfaces)
{
isValid &= ValidateReceiverTypeRuleCore(context, typeSymbol, specialSymbols, accessLocation);
}

return isValid;
}

public static bool ValidateReceiverTypeRuleCore(
SourceProductionContext context,
ITypeSymbol typeSymbol,
SpecialSymbols specialSymbols,
Location accessLocation)
{
bool isValid = true;

foreach (ISymbol memberSymbol in receiverTypeSymbol.GetMembers())
foreach (ISymbol memberSymbol in typeSymbol.GetMembers())
{
if (memberSymbol is IMethodSymbol methodSymbol)
{
Expand Down