C # shortcut for #if ... #else ... #endif as #define something as string
In C # dotNET for Mono, is there an easier way to do this?
#if __MonoCS__
public static SqliteConnection NewConnection
#else
public static SQLiteConnection NewConnection
#endif
In C, I could #if and then #define something, #else and define it as something else.
I know the C # preprocessor doesn't allow what I want, but is there an easier way to deal with the differences between Windows and Linux SQLite?
Thanks
Jim
Thanks to those who answered.
Files that depend on SQLite now contain statements like this at the beginning:
#if __MonoCS__
using Mono.Data.Sqlite;
using SQLiteCommand = Mono.Data.Sqlite.SqliteCommand;
using SQLiteConnection = Mono.Data.Sqlite.SqliteConnection;
using SQLiteException = Mono.Data.Sqlite.SqliteException;
using SQLiteParameter = Mono.Data.Sqlite.SqliteParameter;
using SQLiteTransaction = Mono.Data.Sqlite.SqliteTransaction;
#else
using System.Data.SQLite;
#endif
In C, I would put the whole thing in a .h file and #include where needed. Is there a way to do this in a Mono C # project? None of the things I've tried worked.
Thanks again
Jim
source to share
Well, you can use the alias directive:
#if __MonoCS__
using SQLiteConnection = Foo.Bar.SqliteConnection;
#endif
Then you can use it SQLiteConnection
everywhere within the same file.
You might want to use the adapter pattern to put it in only one piece of code, so that all the rest of the code can be the same.
source to share