[英]Windows Azure cscfg file, presenting enums
I am writing cscfg file.我正在编写 cscfg 文件。 I want to present one of its values to be enum:
我想将其值之一呈现为枚举:
enum Importance
{
None,
Trivial,
Regular,
Important,
Critical
};
I cscfg file I have a following Setting:我的 cscfg 文件我有以下设置:
<Setting name="MySettings" value="None">
For example:例如:
<Setting name="MySettings" value="Kuku">
Read the value just like you read any other configuration in a string.读取值就像读取字符串中的任何其他配置一样。 Then use Enum.TryParse<> to check and convert the string to an enum.
然后使用Enum.TryParse<>检查字符串并将其转换为枚举。
You can use Enum.TryParse
for this:您可以为此使用
Enum.TryParse
:
var value = valueFromConfigFile;
Importance val;
if (Enum.TryParse(value, true, out val)){
// OK, go ahead
}
else{
// enum not recognized
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.