C# shortcut for #if … #else … #endif like #define something as string

后端 未结 1 837
迷失自我
迷失自我 2021-01-25 04:42

In C# dotNET for Mono, is there an easier way of doing this?

#if __MonoCS__
    public static SqliteConnection NewConnection
#else
    public static SQLiteConnec         


        
相关标签:
1条回答
  • 2021-01-25 05:19

    Well, you can use a using alias directive:

    #if __MonoCS__
    using SQLiteConnection = Foo.Bar.SqliteConnection;
    #endif
    

    Then you can use SQLiteConnection everywhere within the same file.

    You may want to use the adapter pattern to put this just in a single piece of code though, so all the rest of your code can be the same either way.

    0 讨论(0)
提交回复
热议问题