/// <summary>
        /// Implements Invoke method of RealProxy. Delegates standard adapter methods to the equivalent proxy methods,
        /// and delegates all other invocations to abstract invoke method.
        /// </summary>
        /// <param name="msg">An IMessage that contains a IDictionary of information about the method call. </param>
        /// <returns>The message returned by the delegated method, containing the return value and any out or ref parameter.</returns>
        public override IMessage Invoke(IMessage msg)
        {
            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }

            IMethodCallMessage methodCall = msg as IMethodCallMessage;

            if (msg == null)
            {
                throw new InvalidOperationException("Method call is expected.");
            }

            if (methodCall.MethodBase == adapterInitializeMethod)
            {
                return(Initialize(methodCall));
            }
            if (methodCall.MethodBase == adapterGetSiteMethod)
            {
                return(GetSite(methodCall));
            }
            if (methodCall.MethodBase == adapterResetMethod)
            {
                return(Reset(methodCall));
            }
            if (methodCall.MethodBase == disposableDisposeMethod)
            {
                return(Dispose(methodCall));
            }
            if (methodCall.MethodBase == objectGetHashCodeMethod)
            {
                return(GetHashCode(methodCall));
            }

            if (TestSite == null)
            {
                throw new InvalidOperationException("Calling method on uninitialized adapter");
            }

            TestSite.CheckErrors();

            return(Invoke(methodCall));
        }
Beispiel #2
0
        /// <summary>
        /// Implements Invoke method of DispatchProxy. Delegates standard adapter methods to the equivalent proxy methods,
        /// and delegates all other invocations to abstract invoke method.
        /// </summary>
        /// <param name="targetMethod">The method the caller invoked.</param>
        /// <param name="args">The arguments the caller passed to the method.</param>
        /// <returns>The object to return to the caller, or null for void methods.</returns>
        protected override object Invoke(MethodInfo targetMethod, object[] args)
        {
            if (targetMethod == null)
            {
                throw new ArgumentNullException("targetMethod");
            }

            if (targetMethod == adapterInitializeMethod)
            {
                return(Initialize(targetMethod, args));
            }
            if (targetMethod == adapterGetSiteMethod)
            {
                return(GetSite(targetMethod));
            }
            if (targetMethod == adapterResetMethod)
            {
                return(Reset(targetMethod));
            }
            if (targetMethod == disposableDisposeMethod)
            {
                return(Dispose(targetMethod));
            }
            if (targetMethod == objectGetHashCodeMethod)
            {
                return(GetHashCode(targetMethod));
            }

            if (TestSite == null)
            {
                throw new InvalidOperationException("Calling method on uninitialized adapter");
            }

            TestSite.CheckErrors();

            return(ExecuteMethod(targetMethod, args));
        }