title: CodeDomSerializer output ordering
body: <p>I have created a component to do some stuff for localization for our project.  The issue I am having is that the code I output that gets injected into the InitializeComponent is happening too late.</p>
  
  <p>Example </p>
  
  <pre><code>this.components = new System.ComponentModel.Container();
  System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ucHome));
  this.localizationResourceManager1 = new Compass0.Localization.LocalizationResourceManager(this.components);
  //Other designer code to create controls (this is all in the first block of code in InitializeComponent 
  Compass0.Localization.XMLResourceManager.Create(typeof(ucViewHome), ref resources);  //created by my code serializier
  //
  // btnLogin
  //
  </code></pre>
  
  <p>etc etc </p>
  
  <p>But what is happening by the designer is </p>
  
  <pre><code>this.components = new System.ComponentModel.Container();
  System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ucHome));
  this.btnLogin = new ComponentFactory.Krypton.Toolkit.KryptonButton();
  this.localizationResourceManager1 = new Compass0.Localization.LocalizationResourceManager(this.components);
  //Other designer code to create controls (this is all in the first block of code in InitializeComponent 
  //
  // btnLogin
  //
  this. btnLogin.Name = "btnLogin"; 
  this. btnLogin.Text = resources.GetString("btnLogin.Text");
  Compass0.Localization.XMLResourceManager.Create(typeof(ucViewHome), ref resources);  //created by my code serializier
  </code></pre>
  
  <p>I basically need to force the designer to put my code on the 3rd line after the resources has been initialized.  Is there a way I can do this in a straight forward manner?  My code generation class is below.</p>
  
  <pre><code>public override object Deserialize( IDesignerSerializationManager manager, object codeDomObject )
      {
          CodeDomSerializer baseSerializer = ( CodeDomSerializer )manager.GetSerializer( typeof( LocalizationResourceManager ).BaseType, typeof( CodeDomSerializer ) );
  
          return baseSerializer.Deserialize( manager, codeDomObject );
      }
  
      public override object Serialize( IDesignerSerializationManager manager, object value )
      {
          CodeDomSerializer baseSerializer = ( CodeDomSerializer )manager.GetSerializer( typeof( LocalizationResourceManager ).
              BaseType, typeof( CodeDomSerializer ) );
  
          object codeObject = baseSerializer.Serialize( manager, value );
  
          if ( codeObject is CodeStatementCollection )
          {
              CodeStatementCollection statements = ( CodeStatementCollection )codeObject;
  
              CodeTypeDeclaration classTypeDeclaration = ( CodeTypeDeclaration )manager.GetService(typeof( CodeTypeDeclaration ) );
  
              CodeExpression typeofExpression = new CodeTypeOfExpression( classTypeDeclaration.Name );
  
              CodeDirectionExpression resourceRef = new CodeDirectionExpression( FieldDirection.Ref, new CodeVariableReferenceExpression( "resources" ) );
  
              CodeExpression ResourceManagerAssignment = new CodeMethodInvokeExpression(
                  new CodeTypeReferenceExpression( typeof(XMLResourceManager).ToString() ),
                  "Create", new CodeExpression[] { typeofExpression, resourceRef } );
  
  
              statements.Insert( 0, new CodeExpressionStatement( ResourceManagerAssignment ) );               
          }
  
          return codeObject;
      }
  </code></pre>