2012-12-18 23 views
0

我正在自定义我自己的配置部分。我想知道是否有可能返回null的元素,这是不存在于配置文件中。例如,考虑:Configuration可用空元素

<myConfig><myElement/></myConfig> 

此基础上的顶部:

public class MyConfig : ConfigurationSection 
{ 
    [ConfigurationProperty ("myElement")] 
    public MyElement MyElement { get { return (MyElement) this["myElement"]; } } 
} 

这将返回MyElement实例即使<myElement/>是不存在的。

我该如何克服这个问题?

回答

1

那么,我意识到有一个MyElement.ElementInformation.IsPresent属性。