I am trying to stick to general naming conventions such as those described in Design Guidelines for Developing Class Libraries. I put every type into its own source file (and partial classes will be split across several files as described in question Naming Conventions for Partial Class Files), using the name of the type as the file name.
Examples:
namespace Demo.Bla // project { enum FlowDirection { } // in file FlowDirection.cs class LayoutManager { } // in file LayoutManager.cs } namespace Demo.Bla.LayoutControllers // folder LayoutControllers in project { class StackPanelLayoutController { } // in file LayoutControllers/StackPanelLayoutController }
But I am not sure I've come up with a clever way of naming source files which contain generic classes. Say that I have following classes, for instance:
namespace Demo.Bla.Collections // folder Collections { class Map<T> { } // in file Map.cs (obviously) class Bag { } // in file Bag.cs (obviously) class Bag<T> : Bag { } // also in file Bag.cs ??? }
Should I put the code of both the non-generic and the generic Bag
classes into the same Bag.cs
file? What are your habits?
The most popular names starting with C in the U.S. are currently Charlotte, Camila, Chloe, Claire, Caroline, Carter, Charles, Caleb, Christopher, and Cameron.
I think the common solution to this problem is to name the file like this:
{ClassName}`{NumberOfGenericParameters}
This would give you this filename:
Bag.cs and Bag`1.cs
This is the way Microsoft handle this issue in frameworks like Asp.net Mvc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With