How to name a property when the preferred name is also the name of the type [duplicate]

♀尐吖头ヾ 提交于 2020-01-04 06:51:52

问题


Possible Duplicate:
Giving a property the same name as its class

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.

Here's a snippet of my code:

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

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.

Is there a best practice for naming properties in this situation?


回答1:


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).



来源:https://stackoverflow.com/questions/2023993/how-to-name-a-property-when-the-preferred-name-is-also-the-name-of-the-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!