Add support custom client hub method name (#23614)
This commit is contained in:
parent
3192da4443
commit
5d170de769
|
|
@ -144,6 +144,10 @@ namespace Microsoft.AspNetCore.SignalR.Internal
|
||||||
paramTypes = paramTypes.Take(paramTypes.Length - 1).ToArray();
|
paramTypes = paramTypes.Take(paramTypes.Length - 1).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var methodName =
|
||||||
|
interfaceMethodInfo.GetCustomAttribute<HubMethodNameAttribute>()?.Name ??
|
||||||
|
interfaceMethodInfo.Name;
|
||||||
|
|
||||||
var generator = methodBuilder.GetILGenerator();
|
var generator = methodBuilder.GetILGenerator();
|
||||||
|
|
||||||
// Declare local variable to store the arguments to IClientProxy.SendCoreAsync
|
// Declare local variable to store the arguments to IClientProxy.SendCoreAsync
|
||||||
|
|
@ -154,7 +158,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal
|
||||||
generator.Emit(OpCodes.Ldfld, proxyField);
|
generator.Emit(OpCodes.Ldfld, proxyField);
|
||||||
|
|
||||||
// The first argument to IClientProxy.SendCoreAsync is this method's name
|
// The first argument to IClientProxy.SendCoreAsync is this method's name
|
||||||
generator.Emit(OpCodes.Ldstr, interfaceMethodInfo.Name);
|
generator.Emit(OpCodes.Ldstr, methodName);
|
||||||
|
|
||||||
// Create an new object array to hold all the parameters to this method
|
// Create an new object array to hold all the parameters to this method
|
||||||
generator.Emit(OpCodes.Ldc_I4, paramTypes.Length); // Stack:
|
generator.Emit(OpCodes.Ldc_I4, paramTypes.Length); // Stack:
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,30 @@ namespace Microsoft.AspNetCore.SignalR.Tests.Internal
|
||||||
await task.OrTimeout();
|
await task.OrTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ProducesImplementationThatProxiesMethodsToIRenamedClientProxyAsync()
|
||||||
|
{
|
||||||
|
var clientProxy = new MockProxy();
|
||||||
|
var typedProxy = TypedClientBuilder<IRenamedTestClient>.Build(clientProxy);
|
||||||
|
|
||||||
|
var objArg = new object();
|
||||||
|
var task = typedProxy.MethodAsync("foo", 42, objArg);
|
||||||
|
Assert.False(task.IsCompleted);
|
||||||
|
|
||||||
|
Assert.Collection(clientProxy.Sends,
|
||||||
|
send =>
|
||||||
|
{
|
||||||
|
Assert.Equal("Method", send.Method);
|
||||||
|
Assert.Equal("foo", send.Arguments[0]);
|
||||||
|
Assert.Equal(42, send.Arguments[1]);
|
||||||
|
Assert.Equal(CancellationToken.None, send.CancellationToken);
|
||||||
|
Assert.Same(objArg, send.Arguments[2]);
|
||||||
|
send.Complete();
|
||||||
|
});
|
||||||
|
|
||||||
|
await task.OrTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SupportsSubInterfaces()
|
public async Task SupportsSubInterfaces()
|
||||||
{
|
{
|
||||||
|
|
@ -189,6 +213,12 @@ namespace Microsoft.AspNetCore.SignalR.Tests.Internal
|
||||||
Task Method(string arg1, int arg2, object arg3);
|
Task Method(string arg1, int arg2, object arg3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface IRenamedTestClient
|
||||||
|
{
|
||||||
|
[HubMethodName("Method")]
|
||||||
|
Task MethodAsync(string arg1, int arg2, object arg3);
|
||||||
|
}
|
||||||
|
|
||||||
public interface IVoidMethodClient
|
public interface IVoidMethodClient
|
||||||
{
|
{
|
||||||
void Method(string arg1, int arg2, object arg3);
|
void Method(string arg1, int arg2, object arg3);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue