A nested enum?

  • Thread starter Thread starter Steven Blair
  • Start date Start date
S

Steven Blair

Hi,

As the title suggests, I am looking for soemthing which would
essentially give me a nested enum, or perhaps someone can suggest a more
suitable approach to my problem.

I have a DLL which allows the user to select which type of DB they are
using and also how to connect (ODBC, OleDb etc) and I want this all
available through one type:

For example

DBType.SQLServer.ODBC or
DBType.MySQL.ODBC etc

So after the DBtype, I need an enum of the DB types, but for each DB, I
would like a further subset of options.

I have tried this using a structure:

public struct DBType
{
SQLServer SQLServer;
};

public enum SQLServer
{
Default = 0,
ODBC = 1,
OleDB
}

But this is not good for the user, since I cant do
DBType.SQLServer.ODBC, instead SQLServer.ODBC.

Any help on this would be appreciated.

Regards,

Steven
 
Hello,

You can use following code as an example.

public abstract class DBType
{
public enum SQLServer
{
Demo,
Direct
}

public enum MySQL
{
Demo,
Direct
}
}

HTH. Cheers.
Maqsood Ahmed [MCP C#,SQL Server]
Kolachi Advanced Technologies
http://www.kolachi.net
 
Hit a bit of a problem with this.

How would I pass this into a method. I need to user to create an
instance of my dll and pass in the DB Type / Connection. Since I do not
have an instance of the DBType (abstract class) I am finding this
difficult.

Any suggestions?

Regards,

Steven
 
Here is an example:

theDll = new DBAccess( DBType.SQLServer.ODBC )

How could I pass this into the constructor (passing as a int would lose
any class information) so I could work out which DB type and conenction
was selected:

//My Constructor
public DBAccess( DBType ) //Unsure what to do here
{
//TODO: If DBtype == SQLServer etc
}

Regards,

Steven
 
I think you'd have to have an overload of your constructor for each enum.

--Bob

public DBAccess(DBType.SQLServer option) {
}

public DBAccess(DBType.MySQL option) {
}
 
Back
Top