Skip to content

Commit

Permalink
Merge pull request #61 from nenoNaninu/update_TypeValidator
Browse files Browse the repository at this point in the history
Update TypeValidator
  • Loading branch information
nenoNaninu authored Jan 9, 2024
2 parents b508200 + 93d61d2 commit 29d5199
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
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

0 comments on commit 29d5199

Please sign in to comment.