I have the following options set:
- "Editor" => "C#" => "Code Cleanup" => "Apply Code Cleanup when saving a document"
- "Editor" => "C#" => "Code Cleanup" => "Make properties auto-implemented"
To reproduce the problem:
- Create a XtraForm, add a control (doesn't matter which) and save it .
Then, you'll have something like this as designer file:
C#namespace Testing.Forms
{
partial class XtraForm1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.labelControl1 = new DevExpress.XtraEditors.LabelControl();
this.SuspendLayout();
//
// labelControl1
//
this.labelControl1.Location = new System.Drawing.Point(85, 68);
this.labelControl1.Name = "labelControl1";
this.labelControl1.Size = new System.Drawing.Size(63, 13);
this.labelControl1.TabIndex = 0;
this.labelControl1.Text = "labelControl1";
//
// XtraForm1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(290, 268);
this.Controls.Add(this.labelControl1);
this.Name = "XtraForm1";
this.Text = "XtraForm1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private DevExpress.XtraEditors.LabelControl labelControl1;
}
}
- Go to the code-behind file and define a property, which returns the added control:
C#public LabelControl Label => labelControl1;
- Save this code-behind file and the code cleanup will produce a little mess.
That's, what I get after the save.:
Code-behind file:
C#public LabelControl Label { get ; private set; }
Designer file:
C#namespace Testing.Forms
{
partial class XtraForm1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
Label = new DevExpress.XtraEditors.LabelControl();
this.SuspendLayout();
//
// labelControl1
//
Label.Location = new System.Drawing.Point(85, 68);
Label.Name = "labelControl1";
Label.Size = new System.Drawing.Size(63, 13);
Label.TabIndex = 0;
Label.Text = "labelControl1";
//
// XtraForm1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(290, 268);
this.Controls.Add(Label);
this.Name = "XtraForm1";
this.Text = "XtraForm1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
}
}
So, the designer file is corrupted and I can't use the designer anymore.
In my opinion, the designer file should never be changed during a code cleanup.
Hi,
Thank you for pointing out this issue and providing code samples.
I have reproduced this behavior when a designer file is corrupted after applying the "Make properties auto-implemented" Code-Cleanup rule.
CodeRush has check on designer-files and doesn't apply the Code Cleanup feature on these files. In your case, Code Cleanup is applied not on a designer-file (on a code-behind file) but the "Make properties auto-implemented" rule also modifies a designer-file. We agree that this behavior is wrong. We will correct code cleanup rules that to not modify designer files in these cases. As soon as we correct it, we will notify you.