解释:
我有一个巨大的项目,它建立在一个坚实的框架之上,在这个框架中,必须连接到数据库的函数根据一些条件的不同而工作(简单地说,我们可以说它是一个真/假布尔值)。简单地说,当它访问数据库时,它可以作为web服务或直接mysql连接进行访问。
现在我开始创建一个Xamarin项目(android),我想导入这个框架,但是,Xamarin不支持mysql。。。尽管框架可以调用webservice来获取mysql数据,但mysql代码的存在阻止了我的xamarin项目的构建。我甚至不能使用“if”,因为仍然有对mysql dll的引用。我将如何分割我的类dll文件,以便这个android项目不加载mysql dll,只加载调用web服务的函数的一部分?
函数的外观示例:

public static void InsertStuff(object stuff, bool useDirectMysql)
{
    if (useDirectMysql)//I would like that this part only appears/works if its not the xamarin project, however, i can't use #if as the framework dll still has a reference to the mysql dll
    {
        //MySqlConnection connection = new MySqlConnection....
        //insert stuff
    }
    else
    {
        //Insert stuff with a web service function.. (compatible with xamarin)
    }
}

最佳答案

实现平台特定功能的模式如下:
在共享项目中创建一个具有InsertStuff方法的接口。
使用DI注入依赖项。
相应地在每个平台项目中实现接口。

10-06 05:36
查看更多