Esempio n. 1
0
        private static void AddMethodCall(MethodBase targetMethod, MulticastDelegate implementation)
        {
            // Verify that the method and the implementation have compatible signatures
            var method = implementation.Method;
            var hasCompatibleMethodSignature = method.HasCompatibleMethodSignatureWith(targetMethod);

            if (!hasCompatibleMethodSignature)
            {
                throw new InvalidOperationException(
                          string.Format(
                              "The delegate you provided does not have a compatible signature with the '{0}' method.",
                              targetMethod.Name));
            }

            MethodCallBinderRegistry.AddBinder(new DelegateBinder(targetMethod, implementation));
        }
Esempio n. 2
0
        public static void With(this Func <MethodBase> methodSelector, IMethodCall methodCall)
        {
            var targetMethod = methodSelector();

            Func <MethodBase, bool> selector = method =>
            {
                // Match the methods by declaring type name and signature
                // Note: The CLR doesn't see the two methods as the same type
                // since one of the other types will be modified by the Deflector library
                var result = method?.DeclaringType?.FullName == targetMethod?.DeclaringType?.FullName &&
                             method.HasCompatibleMethodSignatureWith(targetMethod);

                return(result);
            };

            var binder = new MethodCallBinder(selector, methodCall);

            MethodCallBinderRegistry.AddBinder(binder);
        }
Esempio n. 3
0
        public static void With(this Func <MethodBase, bool> methodSelector, IMethodCall methodCall)
        {
            var binder = new MethodCallBinder(methodSelector, methodCall);

            MethodCallBinderRegistry.AddBinder(binder);
        }