-1

I often read other people's code and once in a while, I saw some code added in a Designer file. when I try to understand why some developers write code in a designer file, I often find myself arguing for hours with them. Is there a Microsoft rule not to do it or is it open for anybody ?

Fred Smith
  • 2,047
  • 3
  • 25
  • 36
  • 4
    Possible duplicate of [Manual editing of \*.designer.cs file](http://stackoverflow.com/questions/16161994/manual-editing-of-designer-cs-file) – Myrtle Oct 27 '16 at 11:18
  • I would counter argue with why would you put code in a designer file? Not sure of a solid reason for it TBH – LDJ Oct 27 '16 at 11:25

1 Answers1

4

The comment in the designer file should say enough:

This code is generated. Modifications will be lost when this code is regenerated.

Therefore, there is a risk: you can lose your modifications and / or additions.

Do note, some generators use #region markup to mark what they will generate. For example LLBLgen. However usually these files are not named with .designer.cs.

As for the discussion, a few arguments:

  • usually designer generated files are partial. So the class can be edited in the other file. If something in the designer file needs changes, best is to use the generator tool instead.
  • Code quality tools like Stylecop and code metrics usually are configured to ignore designer generated files. You might miss important feedback.
Myrtle
  • 5,761
  • 33
  • 47