This question is related but not the same as this: http://stackoverflow.com/questions/40730/how-do-you-give-a-c-auto-property-a-default-value
I love auto-properties, but sometimes I have to do something like this:
private string someName;
public string SomeName
{
get
{
return someName;
}
set
{
someName = value.Trim();
}
}
If I have to do the same thing many times, I start wishing that I did not need to type so many lines/characters of code. I want to be able to intercept the value and change it sort of like so:
public string Somename
{
get;
[Trim]
set;
}
Is there a way to do something like this? Would it be stupid? Is there a better way? Any other general comments? I admit, the example I gave is a bit hypothetical and I cannot locate the exact code now which made me think of this.
Thanks.