在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
类型的属性。
在这种情况下命名属性是否有最佳做法?
答案 0 :(得分:0)
有时,这是不可避免的。
但在这种情况下,我会将该属性命名为“文件”。我从来没有在我自己的项目中出现这种情况,但是在其他一些我已经看过它的工作中,它并不是世界末日(很明显,它是有效的)。