c#的快捷方式#if ..#其他. .#endif类似于#define something as string
本文关键字:#define 类似于 something as string #endif 其他 快捷方式 #if | 更新日期: 2023-09-27 18:18:08
在c# dotNET的Mono,有没有一个更容易的方法做到这一点?
#if __MonoCS__
public static SqliteConnection NewConnection
#else
public static SQLiteConnection NewConnection
#endif
在C中,我可以使用#if,然后#define, #else,然后把它定义为别的东西。
我知道c#预处理器不允许我想要的,但是有没有一种更简单的方法来处理Windows和Linux之间的SQLite差异?
谢谢,
吉姆
感谢那些回答的人。
依赖于SQLite的文件现在在开头包含如下语句:
#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
在C中,我会把所有这些放在一个。h文件中,并在需要的地方#include它。在Mono c#项目中有办法做到这一点吗?
再次感谢,
吉姆
你可以使用using alias指令:
#if __MonoCS__
using SQLiteConnection = Foo.Bar.SqliteConnection;
#endif
那么你可以在同一个文件的任何地方使用SQLiteConnection
。
您可能希望使用适配器模式将其放在一段代码中,因此所有其他代码都可以采用相同的方式。