I have a class that's something like this:
public class Abc
{
public string City
{
get { return _getValue(); }
set { _setValue(value); }
}
public string State
{
get { return _getValue(); }
set { _setValue(value); }
}
private string _getValue()
{
// determine return value via StackTrace and reflection
}
...
}
(Yeah, I know StackTrace/reflection is slow; don't flame me bro)
Given that ALL the properties are declared identically, what I'd LOVE to be able to do is have some simple/clean way to declare them w/o needing to dup the same get/set code over and over.
I need Intellisense on all properties, which precludes the use of eg. ExpandoObject
.
If I were in C/C++ land, I could use a macro, eg:
#define DEFPROP(name) \
public string name \
{ \
get { return _getValue(); } \
set { _setValue(value); } \
} \
then:
public class Abc
{
DEFPROP(City)
DEFPROP(State)
...
}
but of course this is C#.
So... any clever ideas?
#### EDIT ###
I guess my original post wasn't sufficiently clear.
My helper function _getValue() does some customised lookup & processing based on which Property is being called. It doesn't just store/retrieve a simple prop-specific value.
If all I needed were simple values, then I'd just use Automatic Properties
public string { get; set; }
and be done with it, and wouldn't have asked this question.