如何,当preferred名称也是类型的名称命名属性也是、名称、属性、类型

2023-09-06 14:46:33 作者:轉角之後,開始念你

可能重复:   Giving属性相同的名称作为它的类

在working在那里我挣扎着增加属性密封类的解决方案,有人指出,my具有相同名称作为一个类型的属性的命名是自找麻烦。

In working on a solution where I was struggling to "add" properties to a sealed class, someone pointed out that my naming of a property with the same name as a type was asking for trouble.

下面是我的code的一个片段:

Here's a snippet of my code:

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

我会pferred只继承的FileInfo $ P $,但我不能,因为它是密封的。我也想将其命名为的FileInfo (因为这正是它是什么),但要避免以后可能出现的问题。我试图避免愚蠢的名字,如 MyFileInfo ,但我很为难,在如何以最佳方式命名类型的属性的FileInfo

I would have preferred to just inherit FileInfo, but I can't since it's sealed. I'd also like to name it FileInfo (since that's exactly what it is), but want to avoid potential problems later on. I'm trying to avoid silly names like MyFileInfo, but I'm stumped at how best to name the property of type FileInfo.

有没有在这种情况下,命名性的最佳实践?

推荐答案

有时候,这是不可避免的。

Sometimes, it's unavoidable.

但在这种情况下,我会说出财产文件。我从来没有真正有这种情况出现在我自己的项目,但在一些人对我已经看到了我的工作,它不是世界的末日(显然,它是有效的)。

But in this case, I would name that property 'File'. I never actually have this situation come up in my own projects, but in some others I've worked on I've seen it, and it's not the end of the world (and obviously, it's valid).