如果您反映 WPFSystem.Windows.Controls.Control
类,您可以看到:
public class Control : FrameworkElement
{
internal ControlBoolFlags _controlBoolField;
// [...]
internal bool ReadControlFlag(ControlBoolFlags reqFlag);
internal void WriteControlFlag(ControlBoolFlags reqFlag, bool set);
// I think it's clear what they do
// [...]
internal enum ControlBoolFlags : ushort
{
CommandDisabled = 8,
ContainsSelection = 128,
ContentIsItem = 16,
ContentIsNotLogical = 1,
HeaderIsItem = 32,
HeaderIsNotLogical = 4,
IsSpaceKeyDown = 2,
ScrollHostValid = 64,
VisualStateChangeSuspended = 256
}
}
所以我只想知道为什么 MS 选择这种方式来存储布尔值而不是bool
为每个标志使用一个字段。他们只是想为每个字段节省空间,这仅仅是他们的编码风格吗?