I am currently using the System.ComponentModel.Design.Serialization namespace to generate C# code. This code is compiled later by another application.
var manager = new DesignerSerializationManager(host);
using (manager.CreateSession())
{
var serializer = (TypeCodeDomSerializer)manager.GetSerializer(root.GetType(),
typeof(TypeCodeDomSerializer));
type = serializer.Serialize(manager, root, host.Container.Components);
....
}
This would generate C# code like:
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TestForm));
this.SuspendLayout();
//
// TestForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(800, 450);
this.Name = "TestForm";
this.Text = "Form1";
this.ResumeLayout(false);
}
Now I am trying to see if I can create an resx file to complement the gerenated code. As you can see with the line:
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
This references the resx file but if you try and compiled this line, there is a missing resx file. I've been looking for a serializer for the design surface that does this but I cannot find once.
If anyone has any knowledge on this maybe can point me in the right direction?