Hi there,
Currently I have this system which behaves like a miniature version of the Windows Registry, and somewhat easyer to use. (And for other purposes.)
Now, with my Folder class, you can use this method:
Key key = folder.GetKey("mykey");
If the key 'mykey' does not exist in the folder, the returned key will be null.
Now, if you'd like to have it made when it doesn't exist, it's possible to set the overloaded argument bool create to true:
Key key = folder.GetKey("mykey", true);
This is usefull to do this:
folder.GetKey("backColor", true).StringValue = "red";
Now, storing data is very easy. Just add the 'true' argument and set the value. However, getting data is still not nice:
Key key = folder.GetKey("backColor");
if (key == null)
tehcolor = "red";
else
tehcolor = key.StringValue;
To solve this, I've added an overload with a default argument. Now, the above code can be written like this:
tehcolor = folder.Getkey("backColor", true, "red");
Nice. -But- now I have got three overloads:
Key GetKey(string name);
Key GetKey(string name, bool create);
Key GetKey(string name, bool create, string defaultValue);
In fact, all these three methods do something different. It would be best to rename them, but it would be nice if the name would be too long (GetOrCreateKey!?).
Are there any better ways (other than the overloads) to get this functionality?
Thanks,
Sijmen