protected virtual void CoreMagicalSpellInvoke(IRuntimeInvocation runtimeInvocation)
 {
     if ((object)runtimeInvocation.WrappedInstance != null)
     {
         runtimeInvocation.InvocationReturnValue = runtimeInvocation.TargetMethod.Invoke(runtimeInvocation.WrappedInstance, runtimeInvocation.InvocationArguments);
     }
 }
예제 #2
0
		protected override void OnAfterInvoke(bool proceedWithInvocation, IRuntimeInvocation runtimeInvocation, ref Exception thrownException)
		{
			var oldConsoleColor = Console.ForegroundColor;
			Console.ForegroundColor = ConsoleColor.Yellow;
			Console.WriteLine("after invoke: {0}", runtimeInvocation.TargetMethod.ToString());
			Console.ForegroundColor = oldConsoleColor;
		}
 protected virtual void CoreAfterInvoke(bool proceedWithInvocation, IRuntimeInvocation runtimeInvocation, ref Exception thrownException)
 {
     if ((object)runtimeInvocation == null)
     {
         throw new ArgumentNullException(nameof(runtimeInvocation));
     }
 }
예제 #4
0
        protected override void OnAfterInvoke(bool proceedWithInvocation, IRuntimeInvocation runtimeInvocation, ref Exception thrownException)
        {
            ConsoleColor oldConsoleColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("after invoke: {0}", runtimeInvocation.TargetMethod.ToString());
            Console.ForegroundColor = oldConsoleColor;
        }
예제 #5
0
		protected override void OnBeforeInvoke(IRuntimeInvocation runtimeInvocation, out bool proceedWithInvocation)
		{
			var oldConsoleColor = Console.ForegroundColor;
			Console.ForegroundColor = ConsoleColor.Blue;
			Console.WriteLine("before invoke: {0}", runtimeInvocation.TargetMethod.ToString());
			Console.ForegroundColor = oldConsoleColor;
			proceedWithInvocation = true;
		}
예제 #6
0
        protected override void OnBeforeInvoke(IRuntimeInvocation runtimeInvocation, out bool proceedWithInvocation)
        {
            ConsoleColor oldConsoleColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("before invoke: {0}", runtimeInvocation.TargetMethod.ToString());
            Console.ForegroundColor = oldConsoleColor;
            proceedWithInvocation   = true;
        }
예제 #7
0
		protected override void OnMagicalSpellInvoke(IRuntimeInvocation runtimeInvocation)
		{
			var oldConsoleColor = Console.ForegroundColor;
			Console.ForegroundColor = ConsoleColor.Green;
			Console.WriteLine("magic invoke: {0}", runtimeInvocation.TargetMethod.ToString());
			Console.ForegroundColor = oldConsoleColor;

			base.OnMagicalSpellInvoke(runtimeInvocation);
		}
        protected override async ValueTask <bool> CoreBeforeInvokeAsync(IRuntimeInvocation runtimeInvocation, CancellationToken cancellationToken = default)
        {
            ConsoleColor oldConsoleColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Blue;
            await Console.Out.WriteLineAsync(string.Format("before invoke: {0}", runtimeInvocation.TargetMethod.ToString()));

            Console.ForegroundColor = oldConsoleColor;
            return(true);
        }
예제 #9
0
        protected override void OnMagicalSpellInvoke(IRuntimeInvocation runtimeInvocation)
        {
            ConsoleColor oldConsoleColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("magic invoke: {0}", runtimeInvocation.TargetMethod.ToString());
            Console.ForegroundColor = oldConsoleColor;

            base.OnMagicalSpellInvoke(runtimeInvocation);
        }
        protected override async ValueTask CoreMagicalSpellInvokeAsync(IRuntimeInvocation runtimeInvocation, CancellationToken cancellationToken = default)
        {
            ConsoleColor oldConsoleColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Green;
            await Console.Out.WriteLineAsync(string.Format("magic invoke: {0}", runtimeInvocation.TargetMethod.ToString()));

            Console.ForegroundColor = oldConsoleColor;

            await base.CoreMagicalSpellInvokeAsync(runtimeInvocation, cancellationToken);
        }
예제 #11
0
        /// <summary>
        /// Represents a discrete run-time invocation.
        /// </summary>
        /// <param name="runtimeInvocation"> </param>
        /// <param name="runtimeContext"> </param>
        public void Invoke(IRuntimeInvocation runtimeInvocation, IRuntimeContext runtimeContext)
        {
            if ((object)runtimeInvocation == null)
            {
                throw new ArgumentNullException(nameof(runtimeInvocation));
            }

            if ((object)runtimeInvocation == null)
            {
                throw new ArgumentNullException(nameof(runtimeContext));
            }

            this.OnInvoke(runtimeInvocation, runtimeContext);
        }
예제 #12
0
		protected override void OnInvoke(IRuntimeInvocation runtimeInvocation, IRuntimeContext runtimeContext)
		{
			this.LastOperationName = string.Format("{0}::{1}", (object)runtimeInvocation.TargetType == null ? "<null>" : runtimeInvocation.TargetType.Name, (object)runtimeInvocation.TargetMethod == null ? "<null>" : runtimeInvocation.TargetMethod.Name);

			if ((object)runtimeInvocation.TargetMethod != null)
			{
				if (runtimeInvocation.TargetMethod.DeclaringType == typeof(object) ||
					runtimeInvocation.TargetMethod.DeclaringType == typeof(IDisposable) ||
					runtimeInvocation.TargetMethod.DeclaringType == typeof(IMockCloneable))
					runtimeInvocation.InvocationReturnValue = runtimeInvocation.TargetMethod.Invoke(this, runtimeInvocation.InvocationArguments);
			}

			throw new InvalidOperationException(string.Format("Method '{0}' not supported on '{1}'.", (object)runtimeInvocation.TargetMethod == null ? "<null>" : runtimeInvocation.TargetMethod.Name, runtimeInvocation.TargetType.FullName));
		}
        protected override void OnInvoke(IRuntimeInvocation runtimeInvocation, IRuntimeContext runtimeContext)
        {
            this.LastOperationName = string.Format("{0}::{1}", (object)runtimeInvocation.TargetType == null ? "<null>" : runtimeInvocation.TargetType.Name, (object)runtimeInvocation.TargetMethod == null ? "<null>" : runtimeInvocation.TargetMethod.Name);

            if ((object)runtimeInvocation.TargetMethod != null)
            {
                if (runtimeInvocation.TargetMethod.DeclaringType == typeof(object) ||
                    runtimeInvocation.TargetMethod.DeclaringType == typeof(IDisposable) ||
                    runtimeInvocation.TargetMethod.DeclaringType == typeof(IMockCloneable))
                {
                    runtimeInvocation.InvocationReturnValue = runtimeInvocation.TargetMethod.Invoke(this, runtimeInvocation.InvocationArguments);
                }
            }

            throw new InvalidOperationException(string.Format("Method '{0}' not supported on '{1}'.", (object)runtimeInvocation.TargetMethod == null ? "<null>" : runtimeInvocation.TargetMethod.Name, runtimeInvocation.TargetType.FullName));
        }
        protected virtual void CoreProceedInvoke(IRuntimeInvocation runtimeInvocation, out Exception thrownException)
        {
            if ((object)runtimeInvocation == null)
            {
                throw new ArgumentNullException(nameof(runtimeInvocation));
            }

            try
            {
                thrownException = null;

                this.CoreMagicalSpellInvoke(runtimeInvocation);
            }
            catch (Exception ex)
            {
                thrownException = ex;
            }
        }
        /// <summary>
        /// Represents a discrete run-time invocation.
        /// </summary>
        /// <param name="runtimeInvocation"> </param>
        /// <param name="runtimeContext"> </param>
        public void Invoke(IRuntimeInvocation runtimeInvocation, IRuntimeContext runtimeContext)
        {
            if ((object)runtimeInvocation == null)
            {
                throw new ArgumentNullException(nameof(runtimeInvocation));
            }

            if ((object)runtimeInvocation == null)
            {
                throw new ArgumentNullException(nameof(runtimeContext));
            }

            try
            {
                this.CoreInvoke(runtimeInvocation, runtimeContext);
            }
            catch (Exception ex)
            {
                throw new InterceptionException(string.Format("The runtime invocation failed (see inner exception)."), ex);
            }
        }
        protected virtual void CoreInvoke(IRuntimeInvocation runtimeInvocation, IRuntimeContext runtimeContext)
        {
            Exception thrownException = null;
            bool      proceedWithInvocation;

            if ((object)runtimeInvocation == null)
            {
                throw new ArgumentNullException(nameof(runtimeInvocation));
            }

            if ((object)runtimeContext == null)
            {
                throw new ArgumentNullException(nameof(runtimeContext));
            }

            if (!((object)runtimeInvocation.TargetMethod != null &&
                  runtimeInvocation.TargetMethod.DeclaringType == typeof(IDisposable)) &&
                this.IsDisposed)                 // always forward dispose invocations
            {
                throw new ObjectDisposedException(typeof(RuntimeInterception).FullName);
            }

            this.CoreBeforeInvoke(runtimeInvocation, out proceedWithInvocation);

            if (proceedWithInvocation)
            {
                this.CoreProceedInvoke(runtimeInvocation, out thrownException);
            }

            this.CoreAfterInvoke(proceedWithInvocation, runtimeInvocation, ref thrownException);

            if ((object)thrownException != null)
            {
                runtimeContext.AbortInterceptionChain();
                throw thrownException;
            }
        }
 protected virtual void CoreBeforeInvoke(IRuntimeInvocation runtimeInvocation, out bool proceedWithInvocation)
 {
     proceedWithInvocation = true;
 }
        protected async virtual ValueTask <bool> CoreBeforeInvokeAsync(IRuntimeInvocation runtimeInvocation, CancellationToken cancellationToken = default)
        {
            await Task.CompletedTask;

            return(true);
        }
        protected virtual async ValueTask <Exception> CoreAfterInvokeAsync(bool proceedWithInvocation, IRuntimeInvocation runtimeInvocation, Exception thrownException, CancellationToken cancellationToken = default)
        {
            if ((object)runtimeInvocation == null)
            {
                throw new ArgumentNullException(nameof(runtimeInvocation));
            }

            await Task.CompletedTask;

            return(thrownException);
        }
        protected override async ValueTask <Exception> CoreAfterInvokeAsync(bool proceedWithInvocation, IRuntimeInvocation runtimeInvocation, Exception thrownException, CancellationToken cancellationToken = default)
        {
            ConsoleColor oldConsoleColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;
            await Console.Out.WriteLineAsync(string.Format("after invoke: {0}", runtimeInvocation.TargetMethod.ToString()));

            Console.ForegroundColor = oldConsoleColor;

            return(thrownException);
        }