Repeating the ConfigurationPropertyAttribute
name three times in the code really bothers me.
It so easy to miss a misspelling or copy/paste a property and forget to update one instance of the name.
Declaring a constant only solves one of these problems. Is there a better way?
I tried reflection, but enumerating the attributes seemed much more trouble, and uglier.
[ConfigurationProperty("port", DefaultValue = (int)0, IsRequired = false)]
[IntegerValidator(MinValue = 0, MaxValue = 8080, ExcludeRange = false)]
public int Port
{
get
{
return (int)this["port"];
}
set
{
this["port"] = value;
}
}
I know DRY is just a principle and often, in the real-world, principles must give way to pragmatism. But I'm sure someone has cleaner way?