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


C# IInterceptor.Init方法代码示例

本文整理汇总了C#中IInterceptor.Init方法的典型用法代码示例。如果您正苦于以下问题:C# IInterceptor.Init方法的具体用法?C# IInterceptor.Init怎么用?C# IInterceptor.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IInterceptor的用法示例。


在下文中一共展示了IInterceptor.Init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CachedMethod

	public override int CachedMethod(int p1, int p2)
	{
		int returnValue = 0;

		if (_methodInfo == null)
		{
			_methodInfo = new CallMethodInfo((MethodInfo)MethodBase.GetCurrentMethod());
		}

		InterceptCallInfo info = new InterceptCallInfo();

		info.Object             = this;
		info.CallMethodInfo     = _methodInfo;
		info.ParameterValues[0] = p1;
		info.ParameterValues[1] = p2;
		info.ReturnValue        = returnValue;
		info.InterceptResult    = InterceptResult.Continue;
		info.InterceptType      = InterceptType.BeforeCall;

		if (_interceptor == null)
		{
			_interceptor = new CacheAspect();
			_interceptor.Init(_methodInfo, "MaxCacheTime=500;IsWeak=False");
		}

		// 'BeforeCall' step checks if the method is cached.
		// If it is and the cache is not expired, the Intercept method populates 
		// return value and output parameters with the cached values and 
		// sets info.InterceptResult to InterceptResult.Return.
		// See the [link][file]Aspects/CacheAspect.cs[/file]CacheAspect.BeforeCall[/link] method for details.
		//
		_interceptor.Intercept(info);

		returnValue = (int)info.ReturnValue;

		if (info.InterceptResult != InterceptResult.Return)
		{
			// If the method call is not cached, target method is called.
			//
			returnValue = base.CachedMethod(p1, p2);

			info.ReturnValue     = returnValue;
			info.InterceptResult = InterceptResult.Continue;
			info.InterceptType   = InterceptType.AfterCall;

			// 'AfterCall' step stores parameters and return values in the cache.
			// See the [link][file]Aspects/CacheAspect.cs[/file]CacheAspect.AfterCall[/link] method for details.
			//
			_interceptor.Intercept(info);

			returnValue = (int)info.ReturnValue;
		}

		return returnValue;
	}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:55,代码来源:CacheAspect.cs

示例2: TestMethod

	public override void TestMethod()
	{
		if (_methodInfo == null)
		{
			_methodInfo = new CallMethodInfo((MethodInfo)MethodBase.GetCurrentMethod());
		}

		InterceptCallInfo info = new InterceptCallInfo();

		try
		{
			info.Object          = this;
			info.CallMethodInfo  = _methodInfo;
			info.InterceptResult = InterceptResult.Continue;
			info.InterceptType   = InterceptType.BeforeCall;

			if (_interceptor == null)
			{
				_interceptor = new CounterAspect();
				_interceptor.Init(_methodInfo, null);
			}

			// 'BeforeCall' creates or gets a counter for the method and 
			// registers the current call.
			// See the [link][file]Aspects/CounterAspect.cs[/file]CounterAspect.BeforeCall[/link] method for details.
			//
			_interceptor.Intercept(info);

			if (info.InterceptResult != InterceptResult.Return)
			{
				// Target method call.
				//
				base.TestMethod();
			}
		}
		catch (Exception exception)
		{
			info.Exception       = exception;
			info.InterceptResult = InterceptResult.Continue;
			info.InterceptType   = InterceptType.OnCatch;

			// 'OnCatch' is required to count calls with exceptions.
			//
			_interceptor.Intercept(info);

			if (info.InterceptResult != InterceptResult.Return)
			{
				throw;
			}
		}
		finally
		{
			info.InterceptResult = InterceptResult.Continue;
			info.InterceptType   = InterceptType.OnFinally;

			// 'OnFinally' step adds statistic to the method counter.
			// See the [link][file]Aspects/CounterAspect.cs[/file]CounterAspect.OnFinally[/link] method for details.
			//
			_interceptor.Intercept(info);
		}
	}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:61,代码来源:CounterAspect.cs


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