/src/LinFu.IoC/Configuration/ConstructorMethodBuilder.cs

http://github.com/philiplaureano/LinFu · C# · 33 lines · 17 code · 2 blank · 14 comment · 0 complexity · 516af8f9bb3da855faead6f7072547b8 MD5 · raw file

  1. using System;
  2. using System.Reflection;
  3. using System.Reflection.Emit;
  4. namespace LinFu.IoC.Configuration
  5. {
  6. /// <summary>
  7. /// A method builder that generates dynamic methods using existing constructors.
  8. /// </summary>
  9. public class ConstructorMethodBuilder : BaseMethodBuilder<ConstructorInfo>
  10. {
  11. /// <summary>
  12. /// Returns the declaring type of the target constructor.
  13. /// </summary>
  14. /// <param name="constructor"></param>
  15. /// <returns>The declaring type of the target constructor.</returns>
  16. protected override Type GetReturnType(ConstructorInfo constructor)
  17. {
  18. return constructor.DeclaringType;
  19. }
  20. /// <summary>
  21. /// Emits an instruction that instantiates the type associated with the
  22. /// <paramref name="constructor" />.
  23. /// </summary>
  24. /// <param name="IL">The <see cref="ILGenerator" /> of the target method body.</param>
  25. /// <param name="constructor">The target constructor.</param>
  26. protected override void EmitCall(ILGenerator IL, ConstructorInfo constructor)
  27. {
  28. IL.Emit(OpCodes.Newobj, constructor);
  29. }
  30. }
  31. }