Manual editing of *.designer.cs file

Spook picture Spook · Apr 23, 2013 · Viewed 16.7k times · Source

I'm aware, that the .designer.cs file contains data generated by the visual form designer in Visual Studio. However, I have some additional methods though, which I want to put into the .designer.cs file as well, because these are responsible for lower-level form handling (for example, pieces of my visual state manager).

The InitializeComponent method inside the .designer.cs file has a comment stating, that it is automatically generated and should not be modified by user. Does this restriction apply only to that method or shouldn't the .designer.cs file be edited by user at all? I've noticed, that among others, it contains the Dispose() method, which the user might want to modify - what suggests the first option. I want to be sure, though.

Answer

dahlbyk picture dahlbyk · Apr 23, 2013

You should never modify .designer.cs. Period. Your changes will be overwritten without mercy.

Update: To be a bit more helpful, C# since v3 (VS 2008) has included partial methods, which many designers will now use to let you implement custom behavior.