开发者

Good guidelines on naming bool properties

开发者 https://www.devze.com 2023-02-03 23:21 出处:网络
Generally if there is a property that gets/sets a value for state, I use \"Is\", like: Visibility: .IsVisible

Generally if there is a property that gets/sets a value for state, I use "Is", like:

Visibility:
.IsVisible

But for properties t开发者_如何学Chat gets/sets actions, what is best to use? Like:

Casting shadows:
.CastShadows

Should I use:

.DoesCastShadows

Is there a better alternative?


Much of the library uses something that would be like .IsShadowCastingEnabled.

For example, UIElement defines IsInputMethodEnabled and IsHitTestVisible.

The nice thing about this is that IsXXX makes it very clear that this is a boolean property.


I think CastsShadows would work. Notice s after Cast. It's parallel with Is in that both start with singular verbs (and Does sounds rather tacky).


My preference is to use "Is" for read-only properties; I'd probably use something like "EnableShadows" as a property. It may not be immediately obvious from the name that it's a property rather than a method, but when reading code it should be obvious, and when writing code Intellisense should indicate that it's a property. Further, if one tries to use EnableShadows as a method, the compiler should complain.

0

精彩评论

暂无评论...
验证码 换一张
取 消