private void GenerateConstructor(CodeGeneratorProxy codeGenerator, MixinLevelCodeGeneratorPipelineState manager) { var constructorBodyStatements = new StringBuilder(); #region Mixin Instance Initialization Statement constructorBodyStatements.AppendFormat( "{0} = {1}", MasterWrapperPlan.MixinInstanceDataMemberName, manager.MixinGenerationPlan.MasterWrapperPlan.MixinInstanceInitializationStatement .EnsureEndsWith(";")); #endregion #region Initialize Virtual Member Functions var masterWrapperMemberHelper = new MasterWrapperCodeGeneratorProxyMemberHelper( codeGenerator, manager.CommonState.Context.TypeResolver.Compilation); manager.MixinGenerationPlan.MasterWrapperPlan.VirtualMembers. Map(mw => constructorBodyStatements.Append( GenerateVirtualMemberFunctionInitializationStatement(mw, masterWrapperMemberHelper))); #endregion #region Initialize BaseMasterWrapper Statement constructorBodyStatements.AppendFormat( "base.Initialize( {0}, {1}, new global::System.Collections.Generic.List<global::{2}>{{ {3} }});", MasterWrapperPlan.TargetInstanceConstructorParameterName, MasterWrapperPlan.MixinInstanceDataMemberName, typeof(IMixinInterceptor).GetOriginalFullName(), string.Join(",", manager.MixinGenerationPlan.MixinAttribute.Interceptors .Select <IType, string>(x => x.GenerateActivationExpression()) ) ); #endregion codeGenerator.CreateConstructor( modifiers: "public", parameters: new[] { new KeyValuePair <string, string>( manager.MixinGenerationPlan.ExternalMixinSpecificAutoGeneratedNamespaceName.EnsureEndsWith( ".") + manager.MixinGenerationPlan.RequirementsInterfacePlan.RequirementsInterfaceName, MasterWrapperPlan.TargetInstanceConstructorParameterName) }, constructorInitializer: string.Empty, constructorBody: constructorBodyStatements.ToString()); }
/// <summary> /// Creates simple public constructors that pass all parameters to base. /// <code> /// <![CDATA[ /// public ProtectedWrapper(obj p1, obj p2) : base (p1, p2){} /// ]]></code> /// </summary> /// <param name="codeGenerator"></param> /// <param name="manager"></param> private void ProcessConstructors(CodeGeneratorProxy codeGenerator, MixinLevelCodeGeneratorPipelineState manager) { manager.MixinGenerationPlan.ProtectedWrapperPlan.Constructors .Map(c => codeGenerator.CreateConstructor( modifiers: "public", parameters: c.Parameters.ToKeyValuePair(), constructorInitializer: ": base(" + string.Join(",", c.Parameters.Select(p => p.Name)) + ")", constructorBody: string.Empty ) ); }
private void AddConstructor(CodeGeneratorProxy mixinsClassCodeGenerator, TargetLevelCodeGeneratorPipelineState manager) { const string targetInstanceConstructorParameterName = "target"; var constructorBodyStatements = new StringBuilder(); foreach (var mixin in manager.CodeGenerationPlan.MixinGenerationPlans.Values) { constructorBodyStatements.AppendFormat( "{0} = {1};", mixin.MasterWrapperPlan.MasterWrapperInstanceNameInMixinsContainer, TypeExtensions.GenerateActivationExpression( typeFullName: GetMasterWrapperFullTypeName(mixin), constructorArgs: string.Format( "({0}.{1}) {2}", mixin.ExternalMixinSpecificAutoGeneratedNamespaceName, mixin.RequirementsInterfacePlan.RequirementsInterfaceName, targetInstanceConstructorParameterName)) ); } mixinsClassCodeGenerator.CreateConstructor( modifiers: "public", parameters: new[] { new KeyValuePair <string, string>( manager.TargetSourceTypeDeclaration.Name, targetInstanceConstructorParameterName) }, constructorInitializer: string.Empty, constructorBody: constructorBodyStatements.ToString()); }