Search code examples
c#xamarin.androidservicestackormlite-servicestack

Sharing code between sqlite-net and servicestack ormlite?


I am using sqlite-net to store data on my MonoDroid mobile application. I am wanting to sync this data with a server side service as well.

Would it be possible to share the code for my Entity objects between sqlite-net and Servicestacks ormlite?

The main difference between the two that I can see is declaring the "using namespace" statements at the top of the class for the object. Is it possible to detect the platform and set the using statements based on the platform?

The other difference would be referencing the different dlls for servicestack so I suppose on the mobile app it would not compile if there are references to the servicestack namespaces...

What would a good approach be to achieve sharing of this code?


Solution

  • They're 2 different assemblies that use physically different attribute types, so in order to link them I would use 2 VS.NET/MonoDevelop project solution files with custom build symbols defined in each project so you can do something like:

    #if MONODROID
       using SQLite;
    #else
       using ServiceStack.OrmLite;
    #endif
    

    To minimize the impact you could also keep as many platform differences into specific platform files and include the appropriate one in each solution.

    You can see an example of supporting multiple build environments in ServiceStack.Text JSON, JSV & CSV Text Serializers which has different .sln/.proj files for .NET, MonoTouch, Silverlight 4.0/5.0, Windows Phone and XBox environments.