PageRenderTime 25ms CodeModel.GetById 22ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/LinFu.AOP/FieldFilterAdapter.cs

http://github.com/philiplaureano/LinFu
C# | 35 lines | 18 code | 4 blank | 13 comment | 0 complexity | 135dc83054e9c5357067b013b7434156 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 a functor to an <see cref="IFieldFilter" /> instance.
 9    /// </summary>
10    public class FieldFilterAdapter : IFieldFilter
11    {
12        private readonly Func<FieldReference, bool> _filter;
13
14        /// <summary>
15        ///     Initializes a new instance of the <see cref="FieldFilterAdapter" /> class.
16        /// </summary>
17        /// <param name="filter">The field filter.</param>
18        public FieldFilterAdapter(Func<FieldReference, bool> filter)
19        {
20            _filter = filter;
21        }
22
23
24        /// <summary>
25        ///     Determines whether or not a particular field get or set should be intercepted.
26        /// </summary>
27        /// <param name="hostMethod">The host method.</param>
28        /// <param name="targetField">The target field.</param>
29        /// <returns>Returns <c>true</c> if the field should be intercepted; otherwise, it will return <c>false</c>.</returns>
30        public bool ShouldWeave(MethodReference hostMethod, FieldReference targetField)
31        {
32            return _filter(targetField);
33        }
34    }
35}