/src/LinFu.IoC/Configuration/ConstructorInvoke.cs

http://github.com/philiplaureano/LinFu · C# · 26 lines · 14 code · 1 blank · 11 comment · 0 complexity · ee2aa88ea2f66ad0548efe37120f6541 MD5 · raw file

  1. using System;
  2. using System.Reflection;
  3. using LinFu.IoC.Configuration.Interfaces;
  4. namespace LinFu.IoC.Configuration
  5. {
  6. /// <summary>
  7. /// A class that invokes constructor instances.
  8. /// </summary>
  9. public class ConstructorInvoke : IMethodInvoke<ConstructorInfo>
  10. {
  11. /// <summary>
  12. /// Invokes the <paramref name="targetMethod" /> constructor
  13. /// using the given <paramref name="arguments" />.
  14. /// </summary>
  15. /// <param name="target">The target object instance.</param>
  16. /// <param name="targetMethod">The target method to invoke.</param>
  17. /// <param name="arguments">The arguments to be used with the method.</param>
  18. /// <returns>The method return value.</returns>
  19. public object Invoke(object target, ConstructorInfo targetMethod, params object[] arguments)
  20. {
  21. var declaringType = targetMethod.DeclaringType;
  22. return Activator.CreateInstance(declaringType, arguments);
  23. }
  24. }
  25. }