Skip to content

Commit 94b888d

Browse files
authored
Merge pull request #80 from luhis/develop
Fixed explicit interface member support
2 parents c060bcb + f7c7fb2 commit 94b888d

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

src/JKang.IpcServiceFramework.Client/IpcServiceClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,18 @@ public async Task<TResult> InvokeAsync<TResult>(Expression<Func<TInterface, Task
106106

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

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

119119
TInterface proxy = _proxyGenerator.CreateInterfaceProxyWithoutTarget<TInterface>(interceptor);
120-
Delegate @delegate = lamdaExp.Compile();
120+
Delegate @delegate = lambdaExp.Compile();
121121
@delegate.DynamicInvoke(proxy);
122122

123123
return new IpcRequest

src/JKang.IpcServiceFramework.IntegrationTests/ContractTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ public async Task AsyncOperation()
9898
Assert.True(actual >= 450);
9999
}
100100

101+
[Fact]
102+
public async Task ExplicitInterfaceOperation()
103+
{
104+
int actual = await _client.InvokeAsync(x => x.ExplicitInterfaceMember());
105+
Assert.True(actual == 0);
106+
}
107+
101108
[Fact]
102109
public async Task ThrowException()
103110
{

src/JKang.IpcServiceFramework.IntegrationTests/ITestService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public interface ITestService
1616
byte[] ReverseBytes(byte[] input);
1717
T GetDefaultValue<T>();
1818
Task<long> WaitAsync(int milliseconds);
19+
int ExplicitInterfaceMember();
1920
void ThrowException(string message);
2021
}
2122
}

src/JKang.IpcServiceFramework.IntegrationTests/TestService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public async Task<long> WaitAsync(int milliseconds)
5454
return sw.ElapsedMilliseconds;
5555
}
5656

57+
int ITestService.ExplicitInterfaceMember()
58+
{
59+
return 0;
60+
}
61+
5762
public void ThrowException(string message)
5863
{
5964
throw new Exception(message);

src/JKang.IpcServiceFramework.Server/IpcServiceEndpoint.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected async Task<IpcResponse> GetReponse(IpcRequest request, IServiceScope s
134134
method = method.MakeGenericMethod(request.GenericArguments);
135135
}
136136

137-
object @return;
137+
object @return;
138138
try
139139
{
140140
@return = method.Invoke(service, args);
@@ -178,7 +178,12 @@ public static MethodInfo GetUnambiguousMethod(IpcRequest request, object service
178178
}
179179

180180
MethodInfo method = null; // disambiguate - can't just call as before with generics - MethodInfo method = service.GetType().GetMethod(request.MethodName);
181-
var serviceMethods = service.GetType().GetMethods().Where(m => m.Name == request.MethodName);
181+
182+
var types = service.GetType().GetInterfaces();
183+
184+
var allMethods = types.SelectMany(t => t.GetMethods());
185+
186+
var serviceMethods = allMethods.Where(t => t.Name == request.MethodName).ToList();
182187

183188
foreach (var serviceMethod in serviceMethods)
184189
{

0 commit comments

Comments
 (0)