[英]How are enums represented in a web.config file?
I thought this questions was trivial and that Enums were represented simply with an integer but I was surprised that it wasn't the case ! 我认为这些问题是微不足道的,并且Enums只用一个整数表示,但我很惊讶它并非如此! Here's what I have :
这就是我所拥有的:
I have a custom config file that contains the following TraceEventType Property 我有一个自定义配置文件,其中包含以下TraceEventType属性
[ConfigurationProperty("Severity")]
public TraceEventType Severity
{
get { return (TraceEventType)this["Severity"]; }
set { this["Severity"] = value; }
}
In my config file, I represented this property with the following value : 在我的配置文件中,我使用以下值表示此属性:
...
<FileLog Filename="Test"
Severity="1" />
The result : I got this : 结果:我得到了这个:
System.Configuration.ConfigurationErrorsException: The value of the property 'Severity' cannot be parsed. System.Configuration.ConfigurationErrorsException:无法解析属性“Severity”的值。 The error is: The enumeration value must be one of the following: Critical, Error, Warning, Information, Verbose, Start, Stop, Suspend, Resume, Transfer.
错误是:枚举值必须是以下之一:严重,错误,警告,信息,详细,启动,停止,暂停,恢复,转移。
You should be able to just use the names of your enum values in the config file, just like the error message states. 您应该能够在配置文件中使用枚举值的名称,就像错误消息状态一样。 For example:
例如:
<FileLog Filename="Test" Severity="Verbose" />
The System.Configuration classes will take care of parsing the enum for you. System.Configuration类将负责为您解析枚举。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.