PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 2ms RepoModel.GetById 38ms app.codeStats 0ms

/src/LinFu.IoC/Configuration/Resolvers/ConstructorResolver.cs

http://github.com/philiplaureano/LinFu
C# | 51 lines | 27 code | 4 blank | 20 comment | 0 complexity | 38e5d28177103532bb7efa5e96376336 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Reflection;
 4using LinFu.IoC.Configuration.Interfaces;
 5using LinFu.IoC.Interfaces;
 6
 7namespace LinFu.IoC.Configuration
 8{
 9    /// <summary>
10    ///     Represents the default implementation of the <see cref="IMemberResolver{TMember}" /> class.
11    /// </summary>
12    public class ConstructorResolver : MemberResolver<ConstructorInfo>
13    {
14        /// <summary>
15        ///     Initializes the class with the default values.
16        /// </summary>
17        public ConstructorResolver()
18        {
19        }
20
21        /// <summary>
22        ///     Initializes the class using the custom method finder.
23        /// </summary>
24        /// <param name="getFinder">The functor that will be used to instantiate the method finder.</param>
25        public ConstructorResolver(Func<IServiceContainer,
26            IMethodFinder<ConstructorInfo>> getFinder) : base(getFinder)
27        {
28        }
29
30        /// <summary>
31        ///     Returns the constructors that belong to the <paramref name="concreteType" />.
32        /// </summary>
33        /// <param name="concreteType">The type that contains the list of constructors.</param>
34        /// <returns>A list of constructors that belong to the <paramref name="concreteType" />.</returns>
35        protected override IEnumerable<ConstructorInfo> GetMembers(Type concreteType)
36        {
37            return concreteType.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
38        }
39
40        /// <summary>
41        ///     Returns the parameterless constructor in case the search fails.
42        /// </summary>
43        /// <param name="concreteType">The target type that contains the default constructor.</param>
44        /// <returns>The default constructor.</returns>
45        protected override ConstructorInfo GetDefaultResult(Type concreteType)
46        {
47            return concreteType.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null,
48                new Type[0], null);
49        }
50    }
51}