2017-05-25 61 views
-3

我想將使用ORMLite的Android代碼庫轉換爲它的C#等價物,用於使用SQLite-net PCL nuget包的Xamarin.Android。C#相當於Java代碼片段Xamarin.Android

的Java:

public abstract class DTAbstractEntity { 


} 

import entities.DTAbstractEntity; 
import com.j256.ormlite.field.DatabaseField; 

public abstract class DTAbstractModelEntity<T extends DTAbstractEntity> extends DTAbstractEntity { 

    public final static String ID_FIELD_NAME = "uuid"; 

    @DatabaseField(id = true, canBeNull = false, columnName = ID_FIELD_NAME) 
    protected String uuid; 

    @DatabaseField 
    protected String name; 

    @DatabaseField 
    protected String path; 

    @DatabaseField 
    protected boolean completeResponse; 

    /* GETTERS */ 
    public String getUuid() { return uuid; } 

    public String getName() { 
     return name; 
    } 

    public String getPath() { 
     return path; 
    } 

    public boolean isCompleteResponse() { 
     return completeResponse; 
    } 
} 

import com.j256.ormlite.field.DatabaseField; 
import com.j256.ormlite.table.DatabaseTable; 

@DatabaseTable 
public class DTProfile extends DTAbstractModelEntity { 

    @DatabaseField 
    private int unreadCount; 

    @DatabaseField 
    private boolean linkedInAuthorised; 

    @DatabaseField 
    private boolean hasSubscriptions; 

    @DatabaseField(foreign=true, foreignAutoCreate = true, foreignAutoRefresh = true) 
    private DTLocale localePreference; 

    @DatabaseField 
    private String loginType; //email or social login provider ie twitter, google, facebook etc 

    /* CONSTRUCTOR */ 
    public DTProfile() { 
     //constructor stub - needed by ORMLite 
    } 

    /* GETTERS */ 

    public int getUnreadCount() { 
     return unreadCount; 
    } 

    public boolean isLinkedInAuthorised() { 
     return linkedInAuthorised; 
    } 

    public boolean isHasSubscriptions() { 
     return hasSubscriptions; 
    } 

    public DTLocale getLocalePreference() { 
     return localePreference; 
    } 

    public String getLoginType() { return loginType; } 

} 

任何人都可以在這裏提供了指導,Java代碼移植到了C#相當於

回答

0

我檢查你的最後一個問題:What is the equivalent package of ORMLite used in case of Xamarin.Android application,答案有建議使用SQLite代替OrmLite ,但你沒有給出答案,所以我想你不想替換這個OrmLite包。

然後,您可以使用Xamarin的Binding Library從Android .JAR文件爲Xamarin.Android創建Xamarin.Android Java綁定庫。

我測試下載OrmLite android 5.0 jar package,並在這裏按照official guide來創建一個DLL,工作正常。

enter image description here

enter image description here

如果你想知道如何使用SQLite-net PCL,你可以檢查此:Create a Database with SQLite,你的代碼看起來像只用於創建數據庫表中,該文檔還創建提供樣品,連接數據庫並插入,從數據庫中獲取數據。這是sample code

+0

非常感謝您的回答。我接受了我之前提出的問題的答案:Xamarin.Android應用程序中使用ORMLite的等效包:) –

+0

@santoshkumarpatro,好的,然後讓我檢查文檔和示例,我在我的答案結尾提供了'SQLite - 網絡PCL',這是沒有幫助嗎? –

+0

我正在嘗試該示例。感謝您的鏈接:) –