flags enum are cool

Welcome Forums General PowerShell Q&A flags enum are cool

This topic contains 1 reply, has 2 voices, and was last updated by

11 months, 3 weeks ago.

  • Author
  • #94831

    Points: 541
    Helping Hand
    Rank: Major Contributor

    Wow, I never knew about this easy way to deal with bitmasks.

    [flags()] Enum ErrorTable
      Error1 = 0x01
      Error2 = 0x02
      Error3 = 0x04
      Error4 = 0x08
      Error5 = 0x10
      Error6 = 0x20
    PS C:\> $errorcodes = [ErrorTable]'Error1,Error2'
    PS C:\> $errorcodes
    Error1, Error2
    PS C:\> $errorcodes = [ErrorTable]3
    PS C:\> $errorcodes
    Error1, Error2
    PS C:\> $errorcodes.HasFlag([ErrorTable]'Error2')                                          
  • #95029

    Points: 22
    Rank: Member

    It is indeed a cool feature but I believe the enum keyword only became available in Powershell 5. If you are stuck in the functional abyss of powershell 4 or less then it's still back to inlinining c# code.

The topic ‘flags enum are cool’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort