In some very specific scenarios we would feel the need to perform a specific action for each flag of the source enumeration.
We can write a simple Generic extension method to realize this task.
<DebuggerStepThrough>
<Extension>
<EditorBrowsable(EditorBrowsableState.Always)>
Public Sub ForEachFlag(Of T)(ByVal sender As [Enum],
ByVal action As Action(Of T))
For Each flag As T In sender.Flags(Of T)
action.Invoke(flag)
Next flag
End Sub
Usage Example:
Dim flags As FileAttributes = (FileAttributes.ReadOnly Or FileAttributes.Hidden)
flags.ForEachFlag(Of FileAttributes)(
Sub(ByVal x As FileAttributes)
Console.WriteLine(x.ToString())
End Sub)