Skip to content

Commit

Permalink
Merge pull request #73 from yukimakura/fix/getInterfaceGenerics
Browse files Browse the repository at this point in the history
Fixed type fetching in the part passed to MessagePack.
  • Loading branch information
neuecc authored Feb 1, 2022
2 parents 24dacef + 021d7ff commit 7aa2fc8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/MessagePipe.Interprocess/Workers/NamedPipeWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ async void RunReceiveLoop(Stream pipeStream, Func<CancellationToken, Task>? wait
try
{
var t = AsyncRequestHandlerRegistory.Get(reqTypeName, resTypeName);
var interfaceType = t.GetInterfaces().First(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandler"));
var coreInterfaceType = t.GetInterfaces().First(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandlerCore"));
var interfaceType = t.GetInterfaces().Where(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandler"))
.First(x => x.GetGenericArguments().Any(x => x.FullName == header.RequestType));
var coreInterfaceType = t.GetInterfaces().Where(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandlerCore"))
.First(x => x.GetGenericArguments().Any(x => x.FullName == header.RequestType));
var service = provider.GetRequiredService(interfaceType); // IAsyncRequestHandler<TRequest,TResponse>
var genericArgs = interfaceType.GetGenericArguments(); // [TRequest, TResponse]
var request = MessagePackSerializer.Deserialize(genericArgs[0], message.ValueMemory, options.MessagePackSerializerOptions);
Expand Down
6 changes: 4 additions & 2 deletions src/MessagePipe.Interprocess/Workers/TcpWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ async void RunReceiveLoop(SocketTcpClient client)
try
{
var t = AsyncRequestHandlerRegistory.Get(reqTypeName, resTypeName);
var interfaceType = t.GetInterfaces().First(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandler"));
var coreInterfaceType = t.GetInterfaces().First(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandlerCore"));
var interfaceType = t.GetInterfaces().Where(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandler"))
.First(x => x.GetGenericArguments().Any(x => x.FullName == header.RequestType));
var coreInterfaceType = t.GetInterfaces().Where(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandlerCore"))
.First(x => x.GetGenericArguments().Any(x => x.FullName == header.RequestType));
var service = provider.GetRequiredService(interfaceType); // IAsyncRequestHandler<TRequest,TResponse>
var genericArgs = interfaceType.GetGenericArguments(); // [TRequest, TResponse]
// Unity IL2CPP does not work(can not invoke nongenerics MessagePackSerializer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ async void RunReceiveLoop(Stream pipeStream, Func<CancellationToken, System.Thre
try
{
var t = AsyncRequestHandlerRegistory.Get(reqTypeName, resTypeName);
var interfaceType = t.GetInterfaces().First(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandler"));
var coreInterfaceType = t.GetInterfaces().First(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandlerCore"));
var interfaceType = t.GetInterfaces().Where(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandler"))
.First(x => x.GetGenericArguments().Any(x => x.FullName == header.RequestType));
var coreInterfaceType = t.GetInterfaces().Where(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandlerCore"))
.First(x => x.GetGenericArguments().Any(x => x.FullName == header.RequestType));
var service = provider.GetRequiredService(interfaceType); // IAsyncRequestHandler<TRequest,TResponse>
var genericArgs = interfaceType.GetGenericArguments(); // [TRequest, TResponse]
var request = MessagePackSerializer.Deserialize(genericArgs[0], message.ValueMemory, options.MessagePackSerializerOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ async void RunReceiveLoop(SocketTcpClient client)
try
{
var t = AsyncRequestHandlerRegistory.Get(reqTypeName, resTypeName);
var interfaceType = t.GetInterfaces().First(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandler"));
var coreInterfaceType = t.GetInterfaces().First(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandlerCore"));
var interfaceType = t.GetInterfaces().Where(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandler"))
.First(x => x.GetGenericArguments().Any(x => x.FullName == header.RequestType));
var coreInterfaceType = t.GetInterfaces().Where(x => x.IsGenericType && x.Name.StartsWith("IAsyncRequestHandlerCore"))
.First(x => x.GetGenericArguments().Any(x => x.FullName == header.RequestType));
var service = provider.GetRequiredService(interfaceType); // IAsyncRequestHandler<TRequest,TResponse>
var genericArgs = interfaceType.GetGenericArguments(); // [TRequest, TResponse]
// Unity IL2CPP does not work(can not invoke nongenerics MessagePackSerializer)
Expand Down

0 comments on commit 7aa2fc8

Please sign in to comment.