I've enums as flags like:
[Flags]
public enum ResultValues
{
None = 0,
Red = 1,
Yellow = 2,
Green = 4,
Other = 8
};
In my code I can OR-connect these flags and all works fine.
Now I store variables of this enum type in the settings. If I add a setting entry, I can set as type the enum from above and select/set one (!) of the values as default (e.g. Green).
<Setting Name="FilterResult" Type="MyNamespace.ResultValues" Scope="User">
<Value Profile="(Default)">Green</Value>
</Setting>
But how can I store a combination of values as default - as I can do this in code with
ResultValues.Red | ResultValues.Yellow | ResultValues.Green | ResultValues.Other
You can store the values just by separating them with a comma:
<Value Profile="(Default)">Green, Other</Value>
The built-in parser will convert such a string to the correct "combined" enum value:
ResultValues.Green | ResultValues.Other
Comma separated:
Flags f = Enum.Parse<Flags>("Red,Yellow,Green");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With