1

Just curious what people would name the file that contains the generic interface IRepository<T>.

IRepositoryT.cs?

Update

One minor point to add. Normally, when you change the name of a class file, Visual Studio asks if you want to do a rename on the class as well. In the case of IRepository<T>, no matter what I name the file (IRepository or IRepositoryT or IRepositoryOfT, etc.), the link between the file name and the class name is never established.

devuxer
  • 41,681
  • 47
  • 180
  • 292
  • 7
    "IRepository.cs" should be good enough. –  Jan 04 '10 at 07:15
  • possible duplicate of [Convention for Filenames of Generic Classes](http://stackoverflow.com/questions/804036/convention-for-filenames-of-generic-classes) – nawfal Apr 16 '13 at 18:59

6 Answers6

6

Personally I would use IRepository.cs. The only difference is when I, for a generic class, also has a nongeneric version of the same, either for compatibility with legacy code, or to provide static methods available to any T.

In this case I would name them:

  • IRepository.NonGeneric.cs
  • IRepository.cs
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
2

I would name it as I say it: IRepositoryOfT.cs

Gordon Mackie JoanMiro
  • 3,499
  • 3
  • 34
  • 42
2

I usually just use IRepository.cs. And unless they are very big classes, I tend to keep IRepository and IRepository<T> in the same file. Usually with the non-generic on top, since the generic one usually extends the non-generic one.

When I have split it into two files, I have usually used IRepository(Of T).cs, but the suggestion from others here with IRepositoryOfT.cs sure is a good one. Might use that one :p

Svish
  • 152,914
  • 173
  • 462
  • 620
1

I would go with IRepository.cs

I don't think the fact that the type is generic should make a difference.

Jaco Pretorius
  • 24,380
  • 11
  • 62
  • 94
1

Maybe this is helpful.

Community
  • 1
  • 1
mkus
  • 3,357
  • 6
  • 37
  • 45
0

Depends if you have IRepository also, and you like to keep different interface definitions in different files.

If so, IRepositoryT.cs, or else IRepository.cs

And I'd put it in a folder named Interfaces, but that's me, and I'm a bit OCD in this area

PostMan
  • 6,899
  • 1
  • 43
  • 51
  • I would say "IRepository.cs" and "IRepositoryGeneric.cs" instead. Maybe even include both in the same file and name it "IRepository.cs" –  Jan 04 '10 at 07:23
  • Yeah, I'd go with the same file idea, depending on the size of the interface. Also IRepositoryGeneric.cs is a much better idea! Thanks! – PostMan Jan 04 '10 at 07:25