Suppose I have a class with several properties that correspond to user-defined parameters, such as:
bool StepUpHedge { get; set; }
bool PullOnJump { get; set; }
bool PullOnCross { get; set; }
double MaxStockSpread { get; set; }
double MaxHedgeSpread { get; set; }
(These are just examples, not real code, and anyway what they mean isn't important.)
Now, let's say there are in fact dozens or even hundreds of these user-defined parameters. To deal with saving/loading and (best of all) copying all or some of them from one instance of the class to another can be quite cumbersome.
Obviously, I don't want to just make a single Dictionary<Parameter, object>
to store them all (type safety? boxing? what's that?), but it would be nice to be able to enumerate over them (without reflection), which is causing me to wonder...
What if I made several dictionaries:
public enum BoolParameter { /*...*/ }
public enum DoubleParameter { /*...*/ }
public enum IntParameter { /*...*/ }
Dictionary<BoolParameter, bool> BoolParameters { get; set; }
Dictionary<DoubleParameter, double> DoubleParameters { get; set; }
Dictionary<IntParameter, int> IntParameters { get; set; }
I know this seems very iffy, and there are cleaner ways to deal with properties in general (for instance, by subclassing them into logical groups); but what I can't seem to wrap my head around is how else to provide the full desired functionality in an easily maintainable way.
The desired functionality is: to be able to display all user-defined parameters for a selected instance, select which properties to copy, and copy the values of only those selected properties from one instance to another. By using an enumerable interface for these properties, this becomes quite simple to do -- and adding a new parameter is as simple as adding it to the dictionary. Otherwise, without using reflection, I'm having a hard time seeing it.
Come to think of it, maybe I should be using a strongly typed DataSet for all this...