dennisdoomen / CSharpGuidelines

A set of coding guidelines for C# 9.0, design principles and layout rules for improving the overall quality of your code development.
https://www.csharpcodingguidelines.com
Other
745 stars 272 forks source link

AV1506: Add guidance for generic types #87

Closed bkoelman closed 7 years ago

bkoelman commented 7 years ago

Applies to: "Name a source file to the type it contains (AV1506)"

Consider the next file:

public class TableLoader
{
    // ...
}

public class TableLoader<TKey, TConverter> : TableLoader
{
    // ...
}

Options:

  1. Allow both types to live in the same file, because their names are the same (they only differ in arity)
  2. Split into TableLoader.cs and TableLoader`2.cs (because arity = 2)
  3. Split into TableLoader.cs and TableLoaderTKeyTConverter.cs
  4. Split into TableLoader.cs and TableLoader.generic.cs (nested)

I think it is worth providing guidance on this situation, to align naming accross the entire team. My preference would be 2. Though I often see option 1 in codebases too.

dennisdoomen commented 7 years ago

I usually keep them together, so my preference is option 1.

bkoelman commented 7 years ago

The same for nested types, right?

An alternative would be to put them in partial classes and in separate files, but I'm not a big fan of that.

dennisdoomen commented 7 years ago

Neither am I.