私はxmlファイルを持っています
<Config>
<Allowed></Allowed>
</Config>
Allowed タグは次のように読み取られます。
string isAllowed = (string)xml.Root
.Element("Config")
.Elements("Allowed")
.SingleOrDefault();
isAllowed は、次の場合にデフォルト値の true を取ることになっています
- タグは存在しません
- 存在するが空である
- true、false、yes、no 以外の値を持つ。
これを行うコードは次のとおりです。
if (isAllowed == null)
{
DoSomething();
return true;
}
if (isAllowed.Length == 0)
{
DoSomething();
return true;
}
if (isAllowed.Length != 0)
{
if (isAllowed.ToUpper() != "FALSE" && isAllowed.ToUpper() != "NO")
{
DoSomething();
return true;
}
}
これを行うためのより良い方法が必要ですか?