如果首选名称也是类型的名称,如何命名属性

时间:2010-01-07 22:01:42

标签: c# .net properties naming-conventions

  

可能重复:
  Giving a property the same name as its class

working on a solution where I was struggling to "add" properties to a sealed class中,有人指出my naming of a property with the same name as a type was asking for trouble

以下是我的代码片段:

class BackupFileInfo : IEquatable<BackupFileInfo>
{
    public FileInfo FileInfo { get; set; }
}

我宁愿继承FileInfo,但我不能,因为它是密封的。我还想将其命名为FileInfo(因为它确实如此),但希望以后避免潜在的问题。我试图避免像MyFileInfo那样愚蠢的名字,但我很难知道如何最好地命名FileInfo类型的属性。

在这种情况下命名属性是否有最佳做法?

1 个答案:

答案 0 :(得分:0)

有时,这是不可避免的。

但在这种情况下,我会将该属性命名为“文件”。我从来没有在我自己的项目中出现这种情况,但是在其他一些我已经看过它的工作中,它并不是世界末日(很明显,它是有效的)。