473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

A nested enum?

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

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
5 15206
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

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #2
Maqsood,

Thats exactly what I needed :)

Thanks for your help.

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
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

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #4
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

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #5
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) {
}

"Steven Blair" <st**********@btinternet.com> wrote in message
news:uX*************@tk2msftngp13.phx.gbl...
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

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: a | last post by:
Is it possible to do a nested enum? For example, private enum inside0{a,b,c} private enum inside1{d,e,f} private enum outside{inside0, inside1} outside _variable=outside.inside0.a; //error...
10
by: tapeesh | last post by:
I created a C file say struct.c with the following structure declarations in the same file struct A { union key { int i; float f; }k1;
11
by: Alfonso Morra | last post by:
Hi, I have the ff data types : typedef enum { VAL_LONG , VAL_DOUBLE , VAL_STRING , VAL_DATASET }ValueTypeEnum ;
6
by: B0nj | last post by:
I've got a class in which I want to implement a property that operates like an indexer, for the various colors associated with the class. For instance, I want to be able to do 'set' operations...
3
by: G Patel | last post by:
Compiler won't let me nest switch statements with common labels inside them (in the cases). Why is this a problem (either in terms of standard or in terms of compiler's ability to make sense of...
1
by: Nike | last post by:
I have a small question w.r.t nested class.. I see in many codes nested classes are declared as public.. First, of all my understanding is that you go in for a nested class if you are sure that...
0
by: rgettman | last post by:
Hello, I'm attempting to use Pro*C to create a nested table and send that data to a stored procedure as a parameter. However, I'm getting a Pro*C compiler error that I'll describe below. I'm...
1
by: borophyll | last post by:
The C standard talks about nested declarators, and th only example of nested declarators I can think of are function parameter declarations, which are nested within the function declaration. Are...
2
by: John Doe | last post by:
Hi, I am trying to port some C class routines into C++. THe original functions are use to set/get properties of buttons inside a toolbar : // This function is used to set btton text //...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.