| | 1 | | namespace PropertyGridHelpers.Controls |
| | 2 | | { |
| | 3 | | /// <summary> |
| | 4 | | /// Represents an item displayed in a checklist box for editing bitwise |
| | 5 | | /// enum values (flags). This item stores both the integer flag value |
| | 6 | | /// and a user-friendly caption. |
| | 7 | | /// </summary> |
| | 8 | | public class FlagCheckedListBoxItem : ItemWrapper<int> |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Initializes a new instance of the <see cref="FlagCheckedListBoxItem"/> class |
| | 12 | | /// with the specified flag value and display caption. |
| | 13 | | /// </summary> |
| | 14 | | /// <param name="value">The integer value representing the flag.</param> |
| | 15 | | /// <param name="caption">The caption displayed to the user.</param> |
| 304 | 16 | | public FlagCheckedListBoxItem(int value, string caption) : base(caption, value) |
| 296 | 17 | | { |
| 304 | 18 | | } |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// Gets a value indicating whether this item represents a |
| | 22 | | /// single flag (a single bit set). |
| | 23 | | /// </summary> |
| | 24 | | /// <value> |
| | 25 | | /// <c>true</c> if this value has exactly one bit set; otherwise, <c>false</c>. |
| | 26 | | /// </value> |
| | 27 | | public bool IsFlag => |
| 48 | 28 | | (Value & (Value - 1)) == 0; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Determines whether this flag item is a member of the specified composite flag value. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name="composite"> |
| | 34 | | /// A <see cref="FlagCheckedListBoxItem"/> representing the composite flags to test against. |
| | 35 | | /// </param> |
| | 36 | | /// <returns> |
| | 37 | | /// <c>true</c> if this flag is included in the composite; otherwise, <c>false</c>. |
| | 38 | | /// </returns> |
| | 39 | | public bool IsMemberFlag(FlagCheckedListBoxItem composite) => |
| 44 | 40 | | composite != null && IsFlag && ((Value & composite.Value) == Value); |
| | 41 | | } |
| | 42 | | } |