[英]ConfigurationSection with nullable element
我正在自定義自己的配置部分。 我想知道是否有可能為配置文件中不存在的元素返回null。 例如,考慮:
<myConfig><myElement/></myConfig>
它基於以下內容:
public class MyConfig : ConfigurationSection
{
[ConfigurationProperty ("myElement")]
public MyElement MyElement { get { return (MyElement) this["myElement"]; } }
}
即使<myElement/>
不存在,這也會返回MyElement
的實例。
我該如何克服?
好吧,我意識到有一個MyElement.ElementInformation.IsPresent
屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.