Skip to content

Commit

Permalink
Merge pull request #207 from ForNeVeR/bugfix/206.interface-map
Browse files Browse the repository at this point in the history
Use interface map instead of method name search
  • Loading branch information
neuecc authored Oct 17, 2019
2 parents 88ac998 + 0c4552b commit f310e1f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/MagicOnion/Server/Hubs/StreamingHubHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ public class StreamingHubHandler : IEquatable<StreamingHubHandler>
static readonly MethodInfo messagePackDeserialize = typeof(LZ4MessagePackSerializer).GetMethods()
.First(x => x.Name == "Deserialize" && x.GetParameters().Length == 2 && x.GetParameters()[0].ParameterType == typeof(ArraySegment<byte>));

private static MethodInfo GetInterfaceMethod(Type targetType, Type interfaceType, string targetMethodName)
{
var mapping = targetType.GetInterfaceMap(interfaceType);
var methodIndex = Array.FindIndex(mapping.TargetMethods, mi => mi.Name == targetMethodName);
return mapping.InterfaceMethods[methodIndex];
}

public StreamingHubHandler(MagicOnionOptions options, Type classType, MethodInfo methodInfo)
{
var hubInterface = classType.GetInterfaces().First(x => x.GetTypeInfo().IsGenericType && x.GetGenericTypeDefinition() == typeof(IStreamingHub<,>)).GetGenericArguments()[0];
var interfaceMethod = hubInterface.GetMethods().First(x => x.Name == methodInfo.Name);
var interfaceMethod = GetInterfaceMethod(classType, hubInterface, methodInfo.Name);


this.HubType = classType;
Expand Down

0 comments on commit f310e1f

Please sign in to comment.