gpt4 book ai didi

c# - ConfigurationSection 多个枚举值

转载 作者:行者123 更新时间:2023-11-30 13:48:14 25 4
gpt4 key购买 nike

有没有办法在配置部分设置多个枚举值?

就像您在 .net 中所做的那样 object.Filter = Filter.Update | Filter.Create;

<wacther filter="update, created"/>

是否支持类似的东西?

最佳答案

开箱即用:

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var section = (MySection)ConfigurationManager.GetSection("mySection");
Console.WriteLine(section.Enum);
}
}

public class MySection : ConfigurationSection
{
[ConfigurationProperty("enum")]
public MyEnum Enum
{
get { return (MyEnum)this["enum"]; }
set { this["enum"] = value; }
}
}

[Flags]
public enum MyEnum
{
None = 0,
Foo = 1,
Bar = 2,
Baz = 4
}
}


<configSections>
<section name="mySection" type="ConsoleApplication1.MySection, ConsoleApplication1"/>
</configSections>

<mySection enum="Foo, Bar"/>

打印:Foo、Bar

关于c# - ConfigurationSection 多个枚举值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13174375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com