private static void CreateConstructor(HandlerClassBuildingContext classContext) { const int thisArgIndex = 0; const int codecContainerArgIndex = 1; var constructorBuilder = classContext.Builder.DefineConstructor( MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, new[] { typeof(ICodecContainer) }); var baseConstructor = typeof(object).GetConstructor(Type.EmptyTypes); var il = new MyILGenerator(constructorBuilder.GetILGenerator()); il.Ldarg(thisArgIndex); il.Call(baseConstructor); il.Ldarg(thisArgIndex); il.Ldarg(codecContainerArgIndex); il.Stfld(classContext.Fields.CodecContainer); foreach (var manualCodecField in classContext.Fields.GetAllManualCodecFields()) { il.Ldarg(thisArgIndex); il.Ldarg(codecContainerArgIndex); il.Call(CodecContainerMethods.GetManualCodecFor(manualCodecField.FieldType.GenericTypeArguments[0])); il.Stfld(manualCodecField); } il.Ret(); }