J
John
Hi,
I'm trying to use the FlagsAttribute enum to be able to
provide multiple mutally exclusive flags, my enum is
described as follows:
[Flags]
public enum NoteTypes
{
NoNotes = 0x0,
ProgressionDecision = 0x1,
TextNote = 0x2,
AttachedFile = 0x4,
BulkRegrowRequest = 0x8,
Identified = 0x16,
}
I invoke it by passing in the note types required as a
Bitmask OR then using a bitmask AND to compare which flags
have been selected, as follows:
SomeMethod(NoteTypes.Identified);
SomeMethod(NoteTypes noteType)
{
if (Convert.ToBoolean(m_noteTypes &
NoteTypes.TextNote))
{
MessageBox("Text Note added");
}
if (Convert.ToBoolean(m_noteTypes &
NoteTypes.AttachedFile))
{
MessageBox("Attached file added");
}
if (Convert.ToBoolean(m_noteTypes & NoteTypes.Identified))
{
MessageBox("Identified added");
}
if (Convert.ToBoolean(m_noteTypes &
NoteTypes.ProgressionDecision))
{
MessageBox("progress decision added");
}
if (Convert.ToBoolean(m_noteTypes &
NoteTypes.BulkRegrowRequest))
{
MessageBox("bulk grow added");
}
}
When I try to pass in a note type of 'identified' the bit
mask AND thinks that the bit is in all types, but if I
pass in 'ProgressionDecision' it works correctly i.e only
the progression decision is added.
I'm a doing something wrong in the bitwise compare or the
setting up of the flags enum?
Any help much appreciated.
John
I'm trying to use the FlagsAttribute enum to be able to
provide multiple mutally exclusive flags, my enum is
described as follows:
[Flags]
public enum NoteTypes
{
NoNotes = 0x0,
ProgressionDecision = 0x1,
TextNote = 0x2,
AttachedFile = 0x4,
BulkRegrowRequest = 0x8,
Identified = 0x16,
}
I invoke it by passing in the note types required as a
Bitmask OR then using a bitmask AND to compare which flags
have been selected, as follows:
SomeMethod(NoteTypes.Identified);
SomeMethod(NoteTypes noteType)
{
if (Convert.ToBoolean(m_noteTypes &
NoteTypes.TextNote))
{
MessageBox("Text Note added");
}
if (Convert.ToBoolean(m_noteTypes &
NoteTypes.AttachedFile))
{
MessageBox("Attached file added");
}
if (Convert.ToBoolean(m_noteTypes & NoteTypes.Identified))
{
MessageBox("Identified added");
}
if (Convert.ToBoolean(m_noteTypes &
NoteTypes.ProgressionDecision))
{
MessageBox("progress decision added");
}
if (Convert.ToBoolean(m_noteTypes &
NoteTypes.BulkRegrowRequest))
{
MessageBox("bulk grow added");
}
}
When I try to pass in a note type of 'identified' the bit
mask AND thinks that the bit is in all types, but if I
pass in 'ProgressionDecision' it works correctly i.e only
the progression decision is added.
I'm a doing something wrong in the bitwise compare or the
setting up of the flags enum?
Any help much appreciated.
John