PageRenderTime 109ms CodeModel.GetById 105ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/LinFu.Proxy.Interfaces/FunctorAsInterceptor.cs

http://github.com/philiplaureano/LinFu
C# | 37 lines | 19 code | 5 blank | 13 comment | 2 complexity | 8964008bedefcbdaab5442aba49f1b6f MD5 | raw file
 1using System;
 2using LinFu.AOP.Interfaces;
 3
 4namespace LinFu.Proxy.Interfaces
 5{
 6    /// <summary>
 7    ///     A class that converts a functor into an <see cref="IInterceptor" /> instance.
 8    /// </summary>
 9    public class FunctorAsInterceptor : IInterceptor
10    {
11        private readonly Func<IInvocationInfo, object> _doIntercept;
12
13        /// <summary>
14        ///     Initializes the class with the given <paramref name="intercept">functor</paramref>.
15        /// </summary>
16        /// <param name="intercept">The functor that will be invoked every time a method is called on the proxy type.</param>
17        public FunctorAsInterceptor(Func<IInvocationInfo, object> intercept)
18        {
19            _doIntercept = intercept;
20        }
21
22
23        /// <summary>
24        ///     A method that redirects the method calls to
25        ///     the functor instance.
26        /// </summary>
27        /// <param name="info">The <see cref="IInvocationInfo" /> instance that describes the context of the method call.</param>
28        /// <returns>The return value from the target method.</returns>
29        public object Intercept(IInvocationInfo info)
30        {
31            if (_doIntercept == null)
32                throw new NotImplementedException();
33
34            return _doIntercept(info);
35        }
36    }
37}