Search code examples
c#.netconfigurationconfigurationsectionconfigurationelement

ConfigurationSection multiple enum values


Is there a way to set multiple enum values in a configuration section?

Like you do in .net object.Filter = Filter.Update | Filter.Create;

<wacther filter="update, created"/>

Is something like that supported?


Solution

  • Define a flag enum:

    [Flags]
    enum Filter
    {
        None = 0,
        Update = 1,
        Create = 2
    }
    

    Assume you have a string of enum from your config file:

    var enumString = "update, create";
    

    So you can get the result:

    var result = (Filter) Enum.Parse(typeof (Filter), enumString, true);