Skip to content

Commit

Permalink
Merge pull request jacqueskang#80 from luhis/develop
Browse files Browse the repository at this point in the history
Fixed explicit interface member support
  • Loading branch information
jacqueskang authored Dec 18, 2019
2 parents c060bcb + f7c7fb2 commit 94b888d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/JKang.IpcServiceFramework.Client/IpcServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ public async Task<TResult> InvokeAsync<TResult>(Expression<Func<TInterface, Task

private static IpcRequest GetRequest(Expression exp, MyInterceptor interceptor)
{
if (!(exp is LambdaExpression lamdaExp))
if (!(exp is LambdaExpression lambdaExp))
{
throw new ArgumentException("Only support lamda expresion, ex: x => x.GetData(a, b)");
throw new ArgumentException("Only support lambda expression, ex: x => x.GetData(a, b)");
}

if (!(lamdaExp.Body is MethodCallExpression methodCallExp))
if (!(lambdaExp.Body is MethodCallExpression methodCallExp))
{
throw new ArgumentException("Only support calling method, ex: x => x.GetData(a, b)");
}

TInterface proxy = _proxyGenerator.CreateInterfaceProxyWithoutTarget<TInterface>(interceptor);
Delegate @delegate = lamdaExp.Compile();
Delegate @delegate = lambdaExp.Compile();
@delegate.DynamicInvoke(proxy);

return new IpcRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ public async Task AsyncOperation()
Assert.True(actual >= 450);
}

[Fact]
public async Task ExplicitInterfaceOperation()
{
int actual = await _client.InvokeAsync(x => x.ExplicitInterfaceMember());
Assert.True(actual == 0);
}

[Fact]
public async Task ThrowException()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface ITestService
byte[] ReverseBytes(byte[] input);
T GetDefaultValue<T>();
Task<long> WaitAsync(int milliseconds);
int ExplicitInterfaceMember();
void ThrowException(string message);
}
}
5 changes: 5 additions & 0 deletions src/JKang.IpcServiceFramework.IntegrationTests/TestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public async Task<long> WaitAsync(int milliseconds)
return sw.ElapsedMilliseconds;
}

int ITestService.ExplicitInterfaceMember()
{
return 0;
}

public void ThrowException(string message)
{
throw new Exception(message);
Expand Down
9 changes: 7 additions & 2 deletions src/JKang.IpcServiceFramework.Server/IpcServiceEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected async Task<IpcResponse> GetReponse(IpcRequest request, IServiceScope s
method = method.MakeGenericMethod(request.GenericArguments);
}

object @return;
object @return;
try
{
@return = method.Invoke(service, args);
Expand Down Expand Up @@ -178,7 +178,12 @@ public static MethodInfo GetUnambiguousMethod(IpcRequest request, object service
}

MethodInfo method = null; // disambiguate - can't just call as before with generics - MethodInfo method = service.GetType().GetMethod(request.MethodName);
var serviceMethods = service.GetType().GetMethods().Where(m => m.Name == request.MethodName);

var types = service.GetType().GetInterfaces();

var allMethods = types.SelectMany(t => t.GetMethods());

var serviceMethods = allMethods.Where(t => t.Name == request.MethodName).ToList();

foreach (var serviceMethod in serviceMethods)
{
Expand Down

0 comments on commit 94b888d

Please sign in to comment.