Mercurial > pub > bltoolkit
diff Tools/DocGen/Content/Doc/Aspects/CounterAspect.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tools/DocGen/Content/Doc/Aspects/CounterAspect.cs Thu Mar 27 21:46:09 2014 +0400 @@ -0,0 +1,68 @@ +[BLToolkitGenerated] +public sealed class TestClass : CounterAspectTest.TestClass +{ + private static CallMethodInfo _methodInfo; + private static IInterceptor _interceptor; + + 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); + } + } +}