views:

231

answers:

4

I am using the Settings class in my .NET project. I notice in the editor that only certain types are available to be used as types for the individual properties in the Settings class. What if I wanted to have a property that was an enumeration from my code or a generic collection for instance? How would I implement that?

I'm guessing that I can do it in a separate file using the partial class mechanism (since Settings is already defined as a partial class) but I want to see if anyone agrees with that and if there may be a way to do it within the editor.

A: 

Doing it in a separate file as a part of a partial class is totally acceptable.

GoodEnough
A: 

If you want to be able to populate complex objects through configuration files, I would suggest using some Dependency Injection Framework s.a. Spring.Net.

Manu
+2  A: 
Sung Meister
Thank you, I did not know you could simply specify the type and it would work. Do you know if its possible to specify generic lists for settings in the same way?
Jeffrey Cameron
Settings file basically let you return any type you want, as far as I know. But by Generic lists, you mean generic collections?
Sung Meister
yes, generic collections (though in my case I wanted a list)
Jeffrey Cameron
If you are trying to return different type of generic list depending on configuration data, wouldn't it be better to simply specify the "type" name instead of returning actual collection object?
Sung Meister
+1  A: 

To get a custom class to show in that list, make sure it has a blank constructor as one of it's constructing options. I learned this the hard way

Tom