独自の関数を使用して、さまざまなデータベース テーブルを操作したいと考えています。私は SQLite を使用しているため、テーブルはカスタム クラスを使用して埋められます。私はそれらを再帰的に埋めようとしているので、この構造体と配列を作成しました:
public class cCodesPair
{
public string cCodeKey { get; set; }
public Type CommonCodeClass { get; set; }
public cCodesPair(string key, Type o)
{
this.cCodeKey = key;
this.CommonCodeClass = o;
}
}
private cCodesPair[] codesPairs = new cCodesPair[]
{
new cCodesPair("DESC_UNITS", typeof(SQLEventUnits)),
new cCodesPair("DESC_DISCIPLINE", typeof(SQLDisciplines)),
new cCodesPair("DESC_COUNTRY", typeof(SQLCountries)),
new cCodesPair("DESC_VIDEOS", typeof(SQLVideos)),
new cCodesPair("DESC_ATHLETES", typeof(SQLAthletes))
};
これを作成するアイデアは、配列をループしてテーブルのクエリを作成し、それぞれの辞書を埋めることでした。
それをしようとする関数は次のとおりです。
public void Load<T>(T t, SQLiteConnection conn) where T : Type
{
try
{
var query = conn.Table<T>;
//MORE CODE...
} catch (Exception ex)
{
Debug.WriteLine("Exception")
}
}
配列をループして関数を呼び出すLoad
関数は次のとおりです。
private async Task fillDictionaries()
{
for (int i = 0; i < codesPairs.Length; i++)
{
MasterDescriptions m = new MasterDescriptions();
Type t = codesPairs[i].CommonCodeClass;
m.Load(t, conn);
}
}
しかし、照会されたテーブルは と呼ばれるものであることがわかりType
ました。
SQLEventUnits
Tables 、SQLDisciplines
などを動的に取得したいと思います。誰でも方法を知っていますか?前もって感謝します!