Most efficient way to parse a flagged enum to a list

前端 未结 6 1385
猫巷女王i
猫巷女王i 2021-01-01 09:06

I have a flagged enum and need to retrieve the names of all values set on it.

I am currently taking advantage of the enum\'s ToString() method which returns the eleme

6条回答
  •  庸人自扰
    2021-01-01 09:25

    Enum.Parse will handle the concatenated values outputted by ToString just fine. Proof using the Immediate window:

    ? System.Enum.Parse(typeof(System.AttributeTargets), "Class, Enum")
    Class | Enum
    

    (the second line is the output, which is different in the debugger/immediate window from the generic Enum.ToString() output).

提交回复
热议问题