Dynamic Enums... Is this possible?
-
Ok, lets say you wanted to create a reusable class to communicate with a SQL database. This class has a method called "OpenConnection" wich accepts an aritrary amount of parameters buy you want one of these parameters to be an enumeration of the avialable SQL servers. In other words, you want a drop down list of all servers available at design time. A dynamic enum within the class would work great buy I dont know if it is possible. Is there any way to accomplish this?
-
Ok, lets say you wanted to create a reusable class to communicate with a SQL database. This class has a method called "OpenConnection" wich accepts an aritrary amount of parameters buy you want one of these parameters to be an enumeration of the avialable SQL servers. In other words, you want a drop down list of all servers available at design time. A dynamic enum within the class would work great buy I dont know if it is possible. Is there any way to accomplish this?
Enums are simply a cleaner and more maintainable version of constants. If you were to create an enum at runtime (which is possible, using dynamic compilation or
Reflection.Emit
) what exactly would you do with it? How would you test for it in your calling method? Is there a reason you method can't accept a string array which contains the names of your servers as a parameter? Charlie if(!curlies){ return; }