0
|
1 [BLToolkitGenerated]
|
|
2 public sealed class TestClass : HowTo.Aspects.TestClass
|
|
3 {
|
|
4 private static CallMethodInfo _methodInfo;
|
|
5 private static IInterceptor _interceptor;
|
|
6
|
|
7 public override int CachedMethod(int p1, int p2)
|
|
8 {
|
|
9 int returnValue = 0;
|
|
10
|
|
11 if (_methodInfo == null)
|
|
12 {
|
|
13 _methodInfo = new CallMethodInfo((MethodInfo)MethodBase.GetCurrentMethod());
|
|
14 }
|
|
15
|
|
16 InterceptCallInfo info = new InterceptCallInfo();
|
|
17
|
|
18 info.Object = this;
|
|
19 info.CallMethodInfo = _methodInfo;
|
|
20 info.ParameterValues[0] = p1;
|
|
21 info.ParameterValues[1] = p2;
|
|
22 info.ReturnValue = returnValue;
|
|
23 info.InterceptResult = InterceptResult.Continue;
|
|
24 info.InterceptType = InterceptType.BeforeCall;
|
|
25
|
|
26 if (_interceptor == null)
|
|
27 {
|
|
28 _interceptor = new CacheAspect();
|
|
29 _interceptor.Init(_methodInfo, "MaxCacheTime=500;IsWeak=False");
|
|
30 }
|
|
31
|
|
32 // 'BeforeCall' step checks if the method is cached.
|
|
33 // If it is and the cache is not expired, the Intercept method populates
|
|
34 // return value and output parameters with the cached values and
|
|
35 // sets info.InterceptResult to InterceptResult.Return.
|
|
36 // See the [link][file]Aspects/CacheAspect.cs[/file]CacheAspect.BeforeCall[/link] method for details.
|
|
37 //
|
|
38 _interceptor.Intercept(info);
|
|
39
|
|
40 returnValue = (int)info.ReturnValue;
|
|
41
|
|
42 if (info.InterceptResult != InterceptResult.Return)
|
|
43 {
|
|
44 // If the method call is not cached, target method is called.
|
|
45 //
|
|
46 returnValue = base.CachedMethod(p1, p2);
|
|
47
|
|
48 info.ReturnValue = returnValue;
|
|
49 info.InterceptResult = InterceptResult.Continue;
|
|
50 info.InterceptType = InterceptType.AfterCall;
|
|
51
|
|
52 // 'AfterCall' step stores parameters and return values in the cache.
|
|
53 // See the [link][file]Aspects/CacheAspect.cs[/file]CacheAspect.AfterCall[/link] method for details.
|
|
54 //
|
|
55 _interceptor.Intercept(info);
|
|
56
|
|
57 returnValue = (int)info.ReturnValue;
|
|
58 }
|
|
59
|
|
60 return returnValue;
|
|
61 }
|
|
62 }
|