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