How do you organize C# code in to files?

Jay Bazuzi picture Jay Bazuzi · Dec 1, 2008 · Viewed 8k times · Source

In C#, the questions of what types to create, what members they should have, and what namespaces should hold them, are questions of OO design. They are not the questions I'm interested in here.

Instead, I want to ask how you store these in disk artifacts. Here are some example rules:

  • Put all of an assembly's types in a single source file. One friend who did this said "files are an archiac code organization tool; today I use classview and Collapse to Definitions to browse my code".

  • Put all your code in one assembly. Makes deployment & versioning simpler.

  • Directory structure reflects namespace structure.

  • Each namespace gets its own assembly.

  • Each type goes in its own assembly. (Listed as an extreme example.)

  • Each type gets its own source file.

  • Each member gets its own file; each type gets its own directory. (Listed as an extreme example.)

Answer

chadmyers picture chadmyers · Dec 1, 2008

Whatever you do, just PLEASE do it consistently. I don't believe there is any one single answer (though there are a few wrong ones). But just make sure you stay true to your form as this will be the key for your successor(s) to find things easily.