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

/src/LinFu.AOP/NewInstanceInterceptionAdapter.cs

http://github.com/philiplaureano/LinFu
C# | 38 lines | 19 code | 4 blank | 15 comment | 0 complexity | 3bfbd143e60ac4d4027f10948ccd6b41 MD5 | raw file
 1using System;
 2using LinFu.AOP.Cecil.Interfaces;
 3using Mono.Cecil;
 4
 5namespace LinFu.AOP.Cecil
 6{
 7    /// <summary>
 8    ///     Represents an adapter class that maps <see cref="INewInstanceFilter" /> instances to
 9    ///     functors.
10    /// </summary>
11    public class NewInstanceInterceptionAdapter : INewInstanceFilter
12    {
13        private readonly Func<MethodReference, TypeReference, MethodReference, bool> _filter;
14
15        /// <summary>
16        ///     Initializes a new instance of the <see cref="NewInstanceInterceptionAdapter" /> class.
17        /// </summary>
18        /// <param name="filter">The filter that determines which instances will be intercepted.</param>
19        public NewInstanceInterceptionAdapter(Func<MethodReference, TypeReference, MethodReference, bool> filter)
20        {
21            _filter = filter;
22        }
23
24
25        /// <summary>
26        ///     Determines whether or not a particular constructor call should be intercepted by the postweaver.
27        /// </summary>
28        /// <param name="currentConstructor">The constructor used to instantiate the current instance.</param>
29        /// <param name="concreteType">The concrete type that contains the new instance call.</param>
30        /// <param name="hostMethod">The host method that contains the new operator call.</param>
31        /// <returns>Returns <c>true</c> if the new operator call should be intercepted; otherwise, it should return <c>false</c>.</returns>
32        public bool ShouldWeave(MethodReference currentConstructor, TypeReference concreteType,
33            MethodReference hostMethod)
34        {
35            return _filter(currentConstructor, concreteType, hostMethod);
36        }
37    }
38}