Example #1
0
        private static MethodInfo?GetMethodOnInterfaceTypeImplementedByMethod(Type type, FakeItEasy.Compatibility.MethodInfoWrapper methodWrapper)
        {
            var reflectedType = methodWrapper.ReflectedType;

            if (reflectedType.GetTypeInfo().IsInterface)
            {
                return(null);
            }

            var allInterfaces =
                from i in type.GetInterfaces()
                where TypeImplementsInterface(reflectedType, i)
                select i;

            foreach (var interfaceType in allInterfaces)
            {
                var interfaceMap = reflectedType.GetTypeInfo().GetRuntimeInterfaceMap(interfaceType);

                var foundMethod =
                    (from methodTargetPair in interfaceMap.InterfaceMethods
                     .Zip(interfaceMap.TargetMethods, (interfaceMethod, targetMethod) => new { InterfaceMethod = interfaceMethod, TargetMethod = targetMethod })
                     where methodWrapper.Method.HasSameBaseMethodAs(methodTargetPair.TargetMethod)
                     select MakeGeneric(methodTargetPair.InterfaceMethod, methodWrapper.Method)).FirstOrDefault();

                if (foundMethod is object)
                {
                    return(GetMethodOnTypeThatImplementsInterfaceMethod(type, foundMethod));
                }
            }

            return(null);
        }
Example #2
0
 private static MethodInfo?FindMethodOnTypeThatWillBeInvokedByMethodInfo(Type type, FakeItEasy.Compatibility.MethodInfoWrapper methodWrapper)
 {
     return
         ((from typeMethod in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
           where typeMethod.HasSameBaseMethodAs(methodWrapper.Method)
           select MakeGeneric(typeMethod, methodWrapper.Method)).FirstOrDefault()
          ?? GetMethodOnTypeThatImplementsInterfaceMethod(type, methodWrapper.Method)
          ?? GetMethodOnInterfaceTypeImplementedByMethod(type, methodWrapper));
 }