comparison Tools/DocGen/Content/Doc/Aspects/CounterAspect.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 [BLToolkitGenerated]
2 public sealed class TestClass : CounterAspectTest.TestClass
3 {
4 private static CallMethodInfo _methodInfo;
5 private static IInterceptor _interceptor;
6
7 public override void TestMethod()
8 {
9 if (_methodInfo == null)
10 {
11 _methodInfo = new CallMethodInfo((MethodInfo)MethodBase.GetCurrentMethod());
12 }
13
14 InterceptCallInfo info = new InterceptCallInfo();
15
16 try
17 {
18 info.Object = this;
19 info.CallMethodInfo = _methodInfo;
20 info.InterceptResult = InterceptResult.Continue;
21 info.InterceptType = InterceptType.BeforeCall;
22
23 if (_interceptor == null)
24 {
25 _interceptor = new CounterAspect();
26 _interceptor.Init(_methodInfo, null);
27 }
28
29 // 'BeforeCall' creates or gets a counter for the method and
30 // registers the current call.
31 // See the [link][file]Aspects/CounterAspect.cs[/file]CounterAspect.BeforeCall[/link] method for details.
32 //
33 _interceptor.Intercept(info);
34
35 if (info.InterceptResult != InterceptResult.Return)
36 {
37 // Target method call.
38 //
39 base.TestMethod();
40 }
41 }
42 catch (Exception exception)
43 {
44 info.Exception = exception;
45 info.InterceptResult = InterceptResult.Continue;
46 info.InterceptType = InterceptType.OnCatch;
47
48 // 'OnCatch' is required to count calls with exceptions.
49 //
50 _interceptor.Intercept(info);
51
52 if (info.InterceptResult != InterceptResult.Return)
53 {
54 throw;
55 }
56 }
57 finally
58 {
59 info.InterceptResult = InterceptResult.Continue;
60 info.InterceptType = InterceptType.OnFinally;
61
62 // 'OnFinally' step adds statistic to the method counter.
63 // See the [link][file]Aspects/CounterAspect.cs[/file]CounterAspect.OnFinally[/link] method for details.
64 //
65 _interceptor.Intercept(info);
66 }
67 }
68 }