• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IMethodInvocation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IMethodInvocation的典型用法代码示例。如果您正苦于以下问题:C# IMethodInvocation类的具体用法?C# IMethodInvocation怎么用?C# IMethodInvocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IMethodInvocation类属于命名空间,在下文中一共展示了IMethodInvocation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Invoke

        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            var stopwatch = new Stopwatch();

            var logger = LogManager.GetLogger(input.MethodBase.ReflectedType);

            var declaringType = input.MethodBase.DeclaringType;
            var className = declaringType != null ? declaringType.Name : string.Empty;
            var methodName = input.MethodBase.Name;
            var generic = declaringType != null && declaringType.IsGenericType
                              ? string.Format("<{0}>", string.Join<Type>(", ", declaringType.GetGenericArguments()))
                              : string.Empty;

            var argumentWriter = new List<string>();
            for (var i = 0; i < input.Arguments.Count; i++)
            {
                var argument = input.Arguments[i];
                var argumentInfo = input.Arguments.GetParameterInfo(i);
                argumentWriter.Add(argumentInfo.Name);
            }
            var methodCall = string.Format("{0}{1}.{2}\n{3}", className, generic, methodName, string.Join(",", argumentWriter));

            logger.InfoFormat(@"Entering {0}", methodCall);

            stopwatch.Start();
            var returnMessage = getNext()(input, getNext);
            stopwatch.Stop();

            logger.InfoFormat(@"Exited {0} after {1}ms", methodName, stopwatch.ElapsedMilliseconds);

            return returnMessage;
        }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:32,代码来源:TimingAspect.cs


示例2: Invoke

		public object Invoke(IMethodInvocation invocation)
		{
			Log("Intercepted call : about to invoke method '{0}'", invocation.Method.Name);
			object returnValue = invocation.Proceed();
			Log("Intercepted call : returned '{0}'", returnValue);
			return returnValue;
		}
开发者ID:fgq841103,项目名称:spring-net,代码行数:7,代码来源:CommonLoggingAroundAdvice.cs


示例3: Invoke

        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            Console.WriteLine($"Called: {input.Target.GetType()}.{input.MethodBase.Name}");

            if (input.Arguments.Count > 0)
            {
                Console.WriteLine("\tWith Arguments");

                for (var i = 0; i < input.Arguments.Count; i++)
                {
                    Console.WriteLine($"\tName: {input.Arguments.GetParameterInfo(i)}");
                }
            }

            var handlerDelegate = getNext();

            Console.WriteLine("Execute...");

            var methodReturn = handlerDelegate(input, getNext);

            var result = methodReturn.ReturnValue?.ToString() ?? "(void)";

            if (methodReturn.Exception != null)
            {
                Console.WriteLine($"Exception: {methodReturn.Exception}");
            }

            Console.WriteLine($"Result: {result}");

            return methodReturn;
        }
开发者ID:lurumad,项目名称:unityinterception,代码行数:31,代码来源:TraceCallHandler.cs


示例4: Invoke

 public object Invoke(IMethodInvocation invocation)
 {
     LOG.Debug("Advice executing; calling the advised method [" + invocation.Method.Name + "]");
     object returnValue = invocation.Proceed();
     LOG.Debug("Advice executed; advised method [" + invocation.Method.Name + "] returned " + returnValue);
     return returnValue;
 }
开发者ID:spring-projects,项目名称:spring-net,代码行数:7,代码来源:ConsoleLoggingAroundAdvice.cs


示例5: Invoke

        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            var cacheAttr = GetAttribute(input);
            if (cacheAttr == null) return getNext()(input, getNext);
            string cacheKey = GetCacheKey(cacheAttr, input);

            ICache cacheHandler = CacheProxy.GetCacheHandler(cacheAttr.CacheMode);

            switch (cacheAttr.CacheType)
            {
                case CacheType.Fetch:
                    if (cacheHandler.Contain(cacheAttr.Group, cacheKey))
                    {
                        return input.CreateMethodReturn(cacheHandler.Get(cacheAttr.Group, cacheKey));
                    }
                    else
                    {
                        var r = getNext()(input, getNext);
                        cacheHandler.Add(cacheAttr.Group, cacheKey, r.ReturnValue);
                        return r;
                    }
                case CacheType.Clear:
                    cacheHandler.Remove(cacheAttr.Group, cacheKey);
                    return getNext()(input, getNext);
            }
            return getNext()(input, getNext);
        }
开发者ID:howbigbobo,项目名称:DailyCode,代码行数:27,代码来源:CacheCallHandler.cs


示例6: GetValueKey

 /// <summary>
 /// 根据指定的<see cref="CachingAttribute"/>以及<see cref="IMethodInvocation"/>实例,
 /// 获取与某一特定参数值相关的键名。
 /// </summary>
 /// <param name="cachingAttribute"><see cref="CachingAttribute"/>实例。</param>
 /// <param name="input"><see cref="IMethodInvocation"/>实例。</param>
 /// <returns>与某一特定参数值相关的键名。</returns>
 private string GetValueKey(CachingAttribute cachingAttribute, IMethodInvocation input)
 {
     switch (cachingAttribute.Method)
     {
         // 如果是Remove,则不存在特定值键名,所有的以该方法名称相关的缓存都需要清除
         case CachingMethod.Remove:
             return null;
         // 如果是Get或者Put,则需要产生一个针对特定参数值的键名
         case CachingMethod.Get:
         case CachingMethod.Put:
             if (input.Arguments != null &&
                 input.Arguments.Count > 0)
             {
                 var sb = new StringBuilder();
                 for (int i = 0; i < input.Arguments.Count; i++)
                 {
                     sb.Append(input.Arguments[i].ToString());
                     if (i != input.Arguments.Count - 1)
                         sb.Append("_");
                 }
                 return sb.ToString();
             }
             else
                 return "NULL";
         default:
             throw new InvalidOperationException("无效的缓存方式。");
     }
 }
开发者ID:JBTech,项目名称:Dot.Utility,代码行数:35,代码来源:CachingInterceptionBehavior.cs


示例7: Invoke

        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            this.log.Debug("Before call to: {0}.{1}, parameters: {2}",
                    input.Target,
                    input.MethodBase.Name,
                    this.GetParameters(input));

            var result = getNext()(input, getNext);

            if (result.Exception != null)
            {
                this.log.Error("Exception while calling: {0}, parameters: {1}, ex: {2}",
                    input.MethodBase.Name,
                    this.GetParameters(input),
                    result.Exception);
            }
            else
            {
                this.log.Debug("Call finished: {0}, parameters: {1}, result: {2}",
                    input.MethodBase.Name,
                    this.GetParameters(input),
                    result.ReturnValue);
            }

            return result;
        }
开发者ID:bezysoftware,项目名称:presentations,代码行数:26,代码来源:LoggingInterceptionBehavior.cs


示例8: Invoke

        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            IMethodReturn result = null;

            if (input.MethodBase.IsDefined(typeof(RequiresTransactionAttribute), true))
            {
                try
                {
                    transactionManager.OpenTransaction();
                    this.transactionManager.Connection.QueryFileKey = this.context.GetQueryFile();
                    this.FindAndInjectDataAccessProperties(input);
                    result = getNext().Invoke(input, getNext);
                    if (result.Exception != null){
                        throw result.Exception;
                    }
                    transactionManager.Commit();
                }
                catch (Exception)
                {
                    transactionManager.Rollback();
                    throw;
                }
                finally
                {
                    transactionManager.Release();
                }
            }
            else
            {
                result = getNext().Invoke(input, getNext); //proceed
            }
            return result;
        }
开发者ID:radixeng,项目名称:XInject,代码行数:33,代码来源:TransactionsManagementBehavior.cs


示例9: Invoke

 /// <exception cref="SapphireUserFriendlyException"><c>SapphireUserFriendlyException</c>.</exception>
 public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
 {
     var result = getNext()(input, getNext);
       if (result.Exception == null)
     return result;
       throw new SapphireUserFriendlyException();
 }
开发者ID:butaji,项目名称:Sapphire,代码行数:8,代码来源:ExceptionHandler.cs


示例10: Invoke

		public object Invoke(IMethodInvocation invocation)
		{
			Console.WriteLine("Before {0} on {1}", invocation.Method.Name,  invocation.Method.DeclaringType);
			object returnVal = invocation.Proceed();
			Console.WriteLine("After {0} on {1}", invocation.Method.Name,  invocation.Method.DeclaringType);
			return returnVal;
		}
开发者ID:ralescano,项目名称:castle,代码行数:7,代码来源:LoggerInterceptor.cs


示例11: Invoke

    /// <summary>
    /// Invokes the specified input.
    /// </summary>
    /// <param name="input">The input.</param>
    /// <param name="getNext">The get next.</param>
    /// <returns>The method return result.</returns>
    public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
    {
      foreach (var argument in input.Arguments)
      {
        string target = argument as string;

        if (string.IsNullOrEmpty(target))
        {
          continue;
        }

        if (Regex.Match(target, @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?").Success)
        {
          continue;
        }

        ArgumentException argumentException = new ArgumentException("Invalid e-mail format", input.MethodBase.Name);

        Log.Error("Argument exception", argumentException, this);

        return input.CreateExceptionMethodReturn(argumentException);
      }

      return getNext()(input, getNext);
    }
开发者ID:HydAu,项目名称:sitecore8ecommerce,代码行数:31,代码来源:EmailValueAttribute.cs


示例12: Invoke

		public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
		{
			if (input.Arguments.Count > 0)
			{
				var arguments = new Argument[input.Arguments.Count];

				for (int i = 0; i < input.Arguments.Count; i++)
				{
					arguments[i] = new Argument
					               	{
					              		Name = input.Arguments.ParameterName(i),
					              		Value = input.Arguments[i]
					              	};
				}

				_tape.RecordRequest(arguments, input.MethodBase.ReflectedType, input.MethodBase.Name);
			}

			Console.WriteLine("> Intercepting " + input.MethodBase.Name);
			Console.WriteLine("> Intercepting " + input.MethodBase.ReflectedType);

			IMethodReturn methodReturn = getNext()(input, getNext);

			Console.WriteLine("> Intercepted return value: " + methodReturn.ReturnValue.GetType().Name);

			if (methodReturn.ReturnValue != null)
			{
				_tape.RecordResponse(methodReturn.ReturnValue, input.MethodBase.ReflectedType, input.MethodBase.Name);
			}

			return methodReturn;
		}
开发者ID:yonglehou,项目名称:Betamax.Net,代码行数:32,代码来源:RecordingCallHandler.cs


示例13: Invoke

        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            var methodName = input.MethodBase.Name;
            var target = input.Target;

            return getNext()(input, getNext);
        }
开发者ID:kangkot,项目名称:unity,代码行数:7,代码来源:TestHandler.cs


示例14: Invoke

        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            var className = input.Target.ToString().Split('.').Last();
            var methodName = input.MethodBase.Name;

            // Before invoking the method on the original target.
            _log.Debug("{className}: {function} started.", className, methodName);
            var timer = new Stopwatch();
            timer.Start();

            // Invoke the next behavior in the chain.
            var result = getNext()(input, getNext);

            timer.Stop();

            // After invoking the method on the original target.
            if (result.Exception != null)
            {
                _log.Warning("--- {className}: {function} threw exception {exception}.", className, methodName, result.Exception);
            }
            else
            {
                _log.Debug("--- {className}: {function} returned {returnValue}.", className, methodName, result);
            }
            _log.Information("--- {className}: {function} executed in {executionTime} (in Milliseconds).", className, methodName, timer.Elapsed.TotalMilliseconds);
            return result;
        }
开发者ID:youngaj,项目名称:ConfOrganizer,代码行数:27,代码来源:LoggingBehavior.cs


示例15: Invoke

		public object Invoke(IMethodInvocation invocation)
		{
            ConsoleLoggingAttribute[] consoleLoggingInfo =
                (ConsoleLoggingAttribute[])invocation.Method.GetCustomAttributes(typeof(ConsoleLoggingAttribute), false);

            if (consoleLoggingInfo.Length > 0)
            {
                Color = consoleLoggingInfo[0].Color;
            }

            ConsoleColor currentColor = Console.ForegroundColor;

            Console.ForegroundColor = Color;

            Console.Out.WriteLine(String.Format(
                "Intercepted call : about to invoke method '{0}'", invocation.Method.Name));

            Console.ForegroundColor = currentColor;

            object returnValue = invocation.Proceed();

            Console.ForegroundColor = Color;

            Console.Out.WriteLine(String.Format(
                "Intercepted call : returned '{0}'", returnValue));

            Console.ForegroundColor = currentColor;

			return returnValue;
		}
开发者ID:Binodesk,项目名称:spring-net,代码行数:30,代码来源:ConsoleLoggingAdvice.cs


示例16: Invoke

        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            IMethodReturn result = null;
            Type exceptionHandler = VerifyEspecificHandler(input);

            result = getNext().Invoke(input, getNext);
            if (result.Exception != null)
            {
                if (exceptionHandler == null)
                {
                    ExceptionHandler excepManager = new DefaultExceptionHandler();
                    Type defaultHandler = this.context.Resolve(typeof(ExceptionHandler));
                    if (defaultHandler != null)
                    {
                        excepManager = (ExceptionHandler)Activator.CreateInstance(defaultHandler);
                    }

                    excepManager.Handle(result.Exception);
                }
                else
                {
                    ExceptionHandler exHandler = (ExceptionHandler)Activator.CreateInstance(exceptionHandler);
                    exHandler.Handle(result.Exception);
                    exHandler = null;
                }
            }
            result.Exception = null;
            return result;
        }
开发者ID:radixeng,项目名称:XInject,代码行数:29,代码来源:LogInterceptor.cs


示例17: Invoke

        /// <summary>
        ///  Handle 'around' advice for services
        /// </summary>
        public object Invoke(IMethodInvocation invocation)
        {
            object returnValue = null;

            using (Repository repository = new Repository(Repository.SessionFactory))
            {
                repository.BeginTransaction();

                DomainRegistry.Repository = repository;
                DomainRegistry.Library = null;

                try
                {
                    returnValue = invocation.Proceed();

                    repository.CommitTransaction();
                }
                catch (Exception e)
                {
                    returnValue = ServiceResult.Error(invocation.Method.ReturnType, e);
                }
            }

            return returnValue;
        }
开发者ID:FlukeFan,项目名称:Atlanta,代码行数:28,代码来源:AopAroundAdvice.cs


示例18: FindInterceptorStateByMethodSignature

        object Proxi.IInterceptor.Run(IMethodInvocation mi)
        {
            // tries to find a registered method that matches...
            var interceptorState = FindInterceptorStateByMethodSignature(mi.Method.ExtractSignature());

            var hasInterceptorState = interceptorState != null;
            var hasTargetObject = mi.Target != null;
            var hasTargetMethod = hasInterceptorState && interceptorState.OnInvokeWasRegistered;
            var isOpenGenericMethod = mi.Method.IsGenericMethodDefinition;

            Func<IMethodInvocation, object> call = x => mi.Method.Invoke(mi.Target, mi.Arguments);
            // method wasn't registered but can be inferred from context if a target exist
            if (!hasTargetMethod && hasTargetObject && hasInterceptorState)
            {
                interceptorState.CallbackCollection.Add(new OnInvokeCallback(call));
                hasTargetMethod = true;
            }

            #region Execution
            // executes interceptor...
            if (hasInterceptorState && hasTargetMethod) return interceptorState.Run(mi);
            // executes target: method wasn't registered but target exists, method will be inferred from context and executed on target directly...
            if (!hasTargetMethod && hasTargetObject) return call(mi);
            // unable to execute any operation...
            else throw new InvalidOperationException("Unable to execute method: " + mi.Method.Name + ". Speficy a target object or a target method utilizing Target() or OnInvoke() method.");
            #endregion
        }
开发者ID:nvegamarrero,项目名称:fluentAOP,代码行数:27,代码来源:InterceptorContext.cs


示例19: Invoke

        /// <summary>
        /// Invokes the specified input.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <param name="getNext">The get next.</param>
        /// <returns>Invoke the next handler in the chain</returns>
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            var target = input.Target;

            // Before invoking the method on the original target
            var el = string.Format(
                "{0} {1}",
                // input.MethodBase.DeclaringType != null ? input.MethodBase.DeclaringType.AssemblyQualifiedName : "-",
                input.MethodBase.Module.ScopeName,
                input.MethodBase);

            this.WriteLog(target, string.Format("Invoking method {0} at {1}", el, DateTime.Now.ToLongTimeString()));

            // Invoke the next handler in the chain
            var result = getNext().Invoke(input, getNext);

            var msg = result.Exception != null
                          ? string.Format(
                              "Method {0} threw exception {1} at {2}",
                              el,
                              result.Exception.Message,
                              DateTime.Now.ToLongTimeString())
                          : string.Format(
                              "Method {0} returned {1} at {2}",
                              el,
                              result.ReturnValue,
                              DateTime.Now.ToLongTimeString());

            // After invoking the method on the original target
            this.WriteLog(target, msg);

            return result;
        }
开发者ID:prachwal,项目名称:MDIwithMVP,代码行数:39,代码来源:LoggingCallHandler.cs


示例20: Invoke

        /// <summary>
        /// Implement this method to perform extra treatments before and after
        /// the call to the supplied <paramref name="invocation"/>.
        /// </summary>
        /// <param name="invocation">The method invocation that is being intercepted.</param>
        /// <returns>
        /// The result of the call to the
        /// <see cref="M:AopAlliance.Intercept.IJoinpoint.Proceed"/> method of
        /// the supplied <paramref name="invocation"/>; this return value may
        /// well have been intercepted by the interceptor.
        /// </returns>
        /// <remarks>
        /// 	<p>
        /// Polite implementations would certainly like to invoke
        /// <see cref="M:AopAlliance.Intercept.IJoinpoint.Proceed"/>.
        /// </p>
        /// </remarks>
        /// <exception cref="T:System.Exception">
        /// If any of the interceptors in the chain or the target object itself
        /// throws an exception.
        /// </exception>
        public object Invoke(IMethodInvocation invocation)
        {
            MethodInfo m = invocation.Method;
            if (m.Name.StartsWith("set_") || m.Name.StartsWith("get_"))
                return invocation.Proceed();

            string name = m.Name;

            object[] attribs = m.GetCustomAttributes(typeof(DefinitionAttribute), true);
            if (attribs.Length > 0)
            {

            }

            if (IsCurrentlyInCreation(name))
            {
                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug(name + " currently in creation, created one.");
                }
                return invocation.Proceed();
            }
            if (LOG.IsDebugEnabled)
            {
                LOG.Debug(name + " not in creation, asked the application context for one");
            }

            return _configurableListableObjectFactory.GetObject(name);
        }
开发者ID:thenapoleon,项目名称:spring-net-codeconfig,代码行数:50,代码来源:SpringObjectMethodInterceptor.cs



注:本文中的IMethodInvocation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IMethodMessage类代码示例发布时间:2022-05-24
下一篇:
C# IMethodInfo类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap