/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
- using System;
- using System.Collections.Generic;
- using System.Reflection;
- using LinFu.IoC.Configuration.Interfaces;
- using LinFu.IoC.Interfaces;
- namespace LinFu.IoC.Configuration
- {
- /// <summary>
- /// Represents the default implementation of the <see cref="IMemberResolver{TMember}" /> class.
- /// </summary>
- public class ConstructorResolver : MemberResolver<ConstructorInfo>
- {
- /// <summary>
- /// Initializes the class with the default values.
- /// </summary>
- public ConstructorResolver()
- {
- }
- /// <summary>
- /// Initializes the class using the custom method finder.
- /// </summary>
- /// <param name="getFinder">The functor that will be used to instantiate the method finder.</param>
- public ConstructorResolver(Func<IServiceContainer,
- IMethodFinder<ConstructorInfo>> getFinder) : base(getFinder)
- {
- }
- /// <summary>
- /// Returns the constructors that belong to the <paramref name="concreteType" />.
- /// </summary>
- /// <param name="concreteType">The type that contains the list of constructors.</param>
- /// <returns>A list of constructors that belong to the <paramref name="concreteType" />.</returns>
- protected override IEnumerable<ConstructorInfo> GetMembers(Type concreteType)
- {
- return concreteType.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
- }
- /// <summary>
- /// Returns the parameterless constructor in case the search fails.
- /// </summary>
- /// <param name="concreteType">The target type that contains the default constructor.</param>
- /// <returns>The default constructor.</returns>
- protected override ConstructorInfo GetDefaultResult(Type concreteType)
- {
- return concreteType.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null,
- new Type[0], null);
- }
- }
- }