当前位置: 首页>>代码示例>>C#>>正文


C# IMethodInvocation类代码示例

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


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


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