I'm creating a custom configuration section (inheriting System.Configuration.ConfigurationSection), and I'm wondering if I have to do value validation for a ConfigurationProperty that is a Nullable int. I.e., do I have to do this:
[ConfigurationProperty("NullableInt", IsRequired = true)]
public int? NullableInt
{
get
{
return String.IsNullOrEmpty(Convert.ToString(this["NullableInt"]))
? (int?) null
: Convert.ToInt32(this["NullableInt"]);
}
set
{
this["NullableInt"] = value.HasValue ? Convert.ToString(value) : "";
}
}
Or can I just do something like this:
[ConfigurationProperty("NullableInt", IsRequired = true)]
public int? NullableInt
{
get{ return Convert.ToInt32(this["NullableInt"]); }
set{ this["NullableInt"] = Convert.ToString(value); }
}
Or is there a better way all-together?
Thanks in advance.