PageRenderTime 20ms CodeModel.GetById 17ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/LinFu.AOP.Interfaces/MethodBodyReplacementProviderRegistry.cs

http://github.com/philiplaureano/LinFu
C# | 44 lines | 22 code | 3 blank | 19 comment | 2 complexity | ab9786f938d55bda78110f98b9979588 MD5 | raw file
 1namespace LinFu.AOP.Interfaces
 2{
 3    /// <summary>
 4    ///     Represents a static type that allows users to register a method replacement provider from a single location.
 5    /// </summary>
 6    public static class MethodBodyReplacementProviderRegistry
 7    {
 8        private static readonly object _lock = new object();
 9        private static IMethodReplacementProvider _provider;
10        private static readonly BootStrapRegistry _registry = BootStrapRegistry.Instance;
11
12        /// <summary>
13        ///     Returns the provider that is currently attached to the registry.
14        /// </summary>
15        /// <param name="host">The type that is currently being intercepted.</param>
16        /// <param name="info">The <see cref="IInvocationInfo" /> object that describes the invocation context.</param>
17        /// <returns>
18        ///     A <see cref="IMethodReplacementProvider" /> that will determine the code that will be executed once a target
19        ///     method is called.
20        /// </returns>
21        public static IMethodReplacementProvider GetProvider(object host, IInvocationInfo info)
22        {
23            if (_provider == null)
24                return null;
25
26            return _provider.CanReplace(host, info) ? _provider : null;
27        }
28
29        /// <summary>
30        ///     Assigns the <paramref name="provider" /> to the MethodReplacementProvider registry.
31        /// </summary>
32        /// <returns>
33        ///     A <see cref="IMethodReplacementProvider" /> that will determine the code that will be executed once a target
34        ///     method is called.
35        /// </returns>
36        public static void SetProvider(IMethodReplacementProvider provider)
37        {
38            lock (_lock)
39            {
40                _provider = provider;
41            }
42        }
43    }
44}