简体   繁体   中英

What is the correct file name for the interface “IRepository<T>”

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.

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

我会说出它的名字:IRepositoryOfT.cs

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

I would go with IRepository.cs

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

也许是有帮助的。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM