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

/src/LinFu.AOP.Interfaces/FieldInterceptorRegistry.cs

http://github.com/philiplaureano/LinFu
C# | 45 lines | 25 code | 3 blank | 17 comment | 3 complexity | 4aea687bfdac3ef41231bba13b59cb35 MD5 | raw file
 1namespace LinFu.AOP.Interfaces
 2{
 3    /// <summary>
 4    ///     Represents a registry class that allows users to intercept fields from a single location.
 5    /// </summary>
 6    public class FieldInterceptorRegistry
 7    {
 8        private static readonly object _lock = new object();
 9        private static IFieldInterceptor _interceptor;
10        private static readonly BootStrapRegistry _registry = BootStrapRegistry.Instance;
11
12        /// <summary>
13        ///     Gets current the <see cref="IFieldInterceptionContext" /> associated with the
14        ///     <see cref="FieldInterceptorRegistry" />.
15        /// </summary>
16        /// <param name="context">
17        ///     The <see cref="IFieldInterceptionContext" /> instance that describes the state of the method call
18        ///     when the field getter or setter is called.
19        /// </param>
20        /// <returns>The field interceptor that will be used to preempt field getter and setter calls.</returns>
21        public static IFieldInterceptor GetInterceptor(IFieldInterceptionContext context)
22        {
23            lock (_lock)
24            {
25                if (_interceptor != null && _interceptor.CanIntercept(context))
26                    return _interceptor;
27            }
28
29            return null;
30        }
31
32        /// <summary>
33        ///     Sets current the <see cref="IFieldInterceptionContext" /> that will be associated with the
34        ///     <see cref="FieldInterceptorRegistry" />.
35        /// </summary>
36        /// <param name="interceptor">The field interceptor that will be used to preempt field getter and setter calls.</param>
37        public static void SetInterceptor(IFieldInterceptor interceptor)
38        {
39            lock (_lock)
40            {
41                _interceptor = interceptor;
42            }
43        }
44    }
45}