private void CreateConstructor(ProxyClassBuildingContext classContext, string path, ServiceDescription serviceDescription) { const int thisArgIndex = 0; const int processorArgIndex = 1; const int scopeArgIndex = 2; const int timeoutSettingsArgIndex = 3; const int codecContainerArgIndex = 4; var constructorBuilder = classContext.Builder.DefineConstructor( MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, ConstructorParameterTypes); var baseConstructor = typeof(object).GetConstructor(Type.EmptyTypes); var il = new MyILGenerator(constructorBuilder.GetILGenerator()); il.Ldarg(thisArgIndex); il.Call(baseConstructor); il.Ldarg(thisArgIndex); il.Ldarg(processorArgIndex); il.Stfld(classContext.Fields.Processor); il.Ldarg(thisArgIndex); il.Ldarg(scopeArgIndex); il.Stfld(classContext.Fields.Scope); il.Ldarg(thisArgIndex); il.Ldarg(timeoutSettingsArgIndex); il.Stfld(classContext.Fields.TimeoutSettings); il.Ldarg(thisArgIndex); il.Ldarg(codecContainerArgIndex); il.Stfld(classContext.Fields.CodecContainer); foreach (var manualCodecField in classContext.Fields.GetAllManualCodecFields()) { var type = manualCodecField.FieldType.GenericTypeArguments[0]; ValidateManualCodecType(type); il.Ldarg(thisArgIndex); il.Ldarg(codecContainerArgIndex); il.Call(CodecContainerMethods.GetManualCodecFor(type)); il.Stfld(manualCodecField); } foreach (var subserviceDesc in serviceDescription.Subservices) { var proxyClass = CreateProxyClass(classContext.InterfaceType, subserviceDesc.Type, path + "/" + subserviceDesc.Name); var fieldBuilder = CreateSubserviceField(classContext, subserviceDesc, proxyClass); CreateSubserviceProperty(classContext, subserviceDesc, fieldBuilder); il.Ldarg(thisArgIndex); il.Ldarg(processorArgIndex); il.Ldarg(scopeArgIndex); il.Ldarg(timeoutSettingsArgIndex); il.Ldarg(codecContainerArgIndex); il.Newobj(proxyClass.GetConstructor(ConstructorParameterTypes)); il.Stfld(fieldBuilder); } il.Ret(); }
protected override void EmitCreateCollection(MyILGenerator il, LocalBuilder lengthVar) { il.Newobj(collectionConstructor); }