/// <summary> /// Adds a constructor to the mixin type. /// </summary> /// <param name="typeBuilder">The <see cref="TypeBuilder"/> use to construct the type.</param> /// <param name="mixinType">The mixin <see cref="Type"/> being created.</param> /// <param name="baseTypesField">The <see cref="FieldBuilder"/> which will hold the instances of the base types.</param> /// <param name="serviceProviderField">The <see cref="FieldBuilder"/> which will hold the instance of the dependency injection resolver.</param> private void EmitConstructor( ITypeBuilder typeBuilder, Type mixinType, IFieldBuilder baseTypesField, IFieldBuilder serviceProviderField) { var constructorBuilder = typeBuilder .NewConstructor() .Public() .HideBySig() .SpecialName() .RTSpecialName() .CallingConvention(CallingConventions.HasThis) .Param <object[]>("instances") .Param <IServiceProvider>("serviceProvider"); constructorBuilder .Body() .LdArg0() .LdArg1() .StFld(baseTypesField) .LdArg0() .LdArg2() .StFld(serviceProviderField) .Ret(); }
/// <summary> /// Adds a constructor to the mixin type. /// </summary> /// <param name="typeBuilder">The <see cref="TypeBuilder"/> use to construct the type.</param> /// <param name="baseType">The base <see cref="Type"/> being ducked.</param> /// <param name="baseTypeField">The <see cref="FieldBuilder"/> which will hold the instances of the base types.</param> /// <param name="serviceProviderField">The <see cref="FieldBuilder"/> which will hold the instance of the dependency injection resolver.</param> private void AddConstructor( ITypeBuilder typeBuilder, Type baseType, IFieldBuilder baseTypeField, IFieldBuilder serviceProviderField) { // Build Constructor. var constructorBuilder = typeBuilder .NewConstructor() .Public() .HideBySig() .SpecialName() .RTSpecialName() .CallingConvention(CallingConventions.HasThis) .Param(baseType, "target") .Param <IServiceProvider>("serviceProvider"); constructorBuilder .Body() .LdArg0() .Call(baseType.GetConstructor(new Type[0])) .LdArg0() .LdArg1() .StFld(baseTypeField) .LdArg0() .LdArg2() .StFld(serviceProviderField) .Ret(); }
/// <summary> /// Adds a constructor to the adapter type. /// </summary> /// <param name="typeBuilder">The <see cref="ITypeBuilder"/> use to construct the type.</param> /// <param name="controllerServiceType">The <see cref="Type"/> controllers service implementation.</param> /// <param name="controllerServiceTypeField">The <see cref="IFieldBuilder"/> which will hold the instance of the controllers service implementation type.</param> /// <returns>The <see cref="ConstructorBuilder"/> used to build the constructor.</returns> private IConstructorBuilder AddConstructor( ITypeBuilder typeBuilder, Type controllerServiceType, IFieldBuilder controllerServiceTypeField) { var constructorBuilder = typeBuilder .NewConstructor() .Public() .HideBySig() .SpecialName() .RTSpecialName() .CallingConvention(CallingConventions.HasThis) .Param(controllerServiceType, "controllerService"); constructorBuilder .Body() .LdArg0() .LdArg1() .StFld(controllerServiceTypeField) .Ret(); return(constructorBuilder); }