I’m using Dictionary<string, string> as configuration for instruments, and it’d be easier for my users who don’t know a lot about programming to be able to get autocomplete from Visual Studio.
In Python I can make a Dictionary and access the different values with a dot operator.
d = {'name':'Joe', 'mood':'grumpy'}
d.name
d.mood
Does C# have a way to do this?
I realize all of the problems involved since dictionary is a just a generic collection (how generic? is it just a list of KeyValuePairs? interesting question). I’m not about to write a wrapper class for this to accomplish it (I’d like it to be a bit more flexible than using explicit properties with a custom class).
You can already do that in C# with anonymous types:
Or real types:
And, in C# 4.0 we will have the DLR which will allow adding properties at runtime using the ExpandoObject:
However, I’m not sure that you can do IntelliSense using static analysis in C#.
The closest C# equivalent to what you have is
Which will not support IntelliSense.
If you are making an API, I would use real types.