简体   繁体   English

Windows Azure cscfg 文件,显示枚举

[英]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">
  1. Is it a correct way to present enum in cscfg?在 cscfg 中显示枚举是正确的方法吗?
  2. How do I read this value to actual enum?如何将此值读取到实际枚举? And how do I validate if the value doesn`t match enum?以及如何验证值是否与枚举不匹配?

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.

相关问题 如何在.cscfg文件中为Windows Azure-worker角色设置数据库连接字符串? - How to set Database connection string for Windows azure - worker role in .cscfg file..? 如何更改ASP.NET ConnectionString =“&lt;%$ ConnectionStrings:MyAppConnection%&gt;”从Azure .cscfg文件工作 - How to change ASP.NET ConnectionString=“<%$ ConnectionStrings:MyAppConnection %>” to work from Azure .cscfg file Azure诊断-加密cscfg中的连接字符串 - Azure Diagnostics - encrypting connection string in cscfg 动态更改天蓝色的配置(.cscfg)值 - Dynamically change azure configuration (.cscfg) values Windows Phone 8 - 枚举和数据注释 - Windows Phone 8 - enums & DataAnnotations 在Azure搜索文档中使用枚举 - Using Enums in Azure Search Documents Ruby - 枚举文件 - Ruby - File for Enums 获取.NET枚举的Windows本地化 - Get Windows localization for .NET enums 当我指定.cscfg文件时出现错误<Setting name=“serilog:write-to:AzureDocumentDB.endpointUrl” /> - .cscfg file gives error when i specify <Setting name=“serilog:write-to:AzureDocumentDB.endpointUrl” /> Azure API App客户端未生成枚举 - Azure API App client is not generating enums
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM