How can I make a reference to a TYPE so I can use myreference name subsequently… In its easiest form…
MyInt — derived from int
Then, elsewhere, I would refer to MyInt. The kicker is that I need this “#define” respective within a class definition that would be subclassed and could be a different type. The actual intent is
MyTypeSQLCmd = OleDbCommand
OR
MyTypeSQLCmd = SQLiteCommand
and my subclass would just refer to, and be able to create a new MyTypeSQLCmd();
— let me elaborate a bit more.
I have one class that connects to an OleDB type of database.
I have ANOTHER class that connect to a SQLite database.
I have ANOTHER class that will derive from EITHER of the above, but will have additional functions. So, instead of knowing which back-end I will connect to, I don’t want to have IFs all over the place like…
if(connectingToSQLite)
MyCmd = new SQLiteCommand();
else
MyCmd = new OleDbCommand();
since subsequently, the common methods available that I need are the same references, such as
MyCmd.Parameters.Add(…)
So, I can’t pre-declare the variable as one “type” or another such as
OleDbCommand MyCmd;
SQLiteCommand MyCmd;
I want just one instance, so I was hoping to get sort of an “aliased” type that would be accepted and allow to continue without compiler errors.
Aren’t you really looking for an interface, i.e. IDbCommand