PageRenderTime 102ms CodeModel.GetById 40ms app.highlight 2ms RepoModel.GetById 58ms app.codeStats 1ms

/src/LinFu.Proxy.Interfaces/CallAdapter.cs

http://github.com/philiplaureano/LinFu
C# | 48 lines | 20 code | 8 blank | 20 comment | 0 complexity | 80ce4b95f78a1e7adab9047f4809165f MD5 | raw file
 1using LinFu.AOP.Interfaces;
 2
 3namespace LinFu.Proxy
 4{
 5    /// <summary>
 6    ///     Adapts an <see cref="IInvokeWrapper" /> instance to an
 7    ///     <see cref="IInterceptor" /> instance.
 8    /// </summary>
 9    internal class CallAdapter : IInterceptor
10    {
11        private readonly IInvokeWrapper _wrapper;
12
13        /// <summary>
14        ///     Initializes the CallAdapter class with the <paramref name="wrapper" /> instance.
15        /// </summary>
16        /// <param name="wrapper">
17        ///     The <see cref="IInvokeWrapper" /> instance that will be called every time the interceptor is
18        ///     invoked.
19        /// </param>
20        public CallAdapter(IInvokeWrapper wrapper)
21        {
22            _wrapper = wrapper;
23        }
24
25
26        /// <summary>
27        ///     Intercepts a method call and passes the <see cref="IInvocationInfo" /> arguments
28        ///     down to the <see cref="IInvokeWrapper" /> instance.
29        /// </summary>
30        /// <param name="info">The <see cref="IInvocationInfo" /> instance that describes the method currently being executed.</param>
31        /// <returns>The return value of the target method.</returns>
32        public object Intercept(IInvocationInfo info)
33        {
34            object result = null;
35
36            // Signal the beginning of the method call
37            _wrapper.BeforeInvoke(info);
38
39            // Process the method call itself
40            result = _wrapper.DoInvoke(info);
41
42            // Postprocess the results
43            _wrapper.AfterInvoke(info, result);
44
45            return result;
46        }
47    }
48}