Matthias
Matthias

Reputation: 16199

ConfigurationSection with nullable element

I'm customizing my own configuration section. I'm wondering if it is possible to return null for an element, that is not present in the config file. For instance, consider:

<myConfig><myElement/></myConfig>

This builds on top of:

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

This will return an instance of MyElement even if the <myElement/> is not there.

How can I overcome this?

Upvotes: 0

Views: 110

Answers (1)

Matthias
Matthias

Reputation: 16199

Well, I realized there is a MyElement.ElementInformation.IsPresent property.

Upvotes: 1

Related Questions