jeudi 22 octobre 2015

SQLite doesn't create table using a Type[] array

I'm trying to fill an SQLite.Net-PCL database using a generic class with extended subclasses. The code for that super-class looks like that:

public class Master
{
    string code;
    string desc;
}

public class Class1 : Master { }

public class Class2 : Master
{
    bool c;
}

//MORE SUB-CLASSES 

I would like to make the creation of the database table automatic this way:

public class DescriptionsDAO
    {
        private SQLiteConnection _conn;
        private Type[] _commonCodes;

        public DescriptionsDAO(SQLiteConnection conn)
        {
            _conn = conn;
            _commonCodes = GetTypesInNamespace(typeof(App).GetTypeInfo().Assembly, "OVPRio2016.Utilities.SQLite.Classes");

            for (int i = 1; i < _commonCodes.Length; i++)
            {
                int r = _conn.CreateTable(_commonCodes[i]);
                System.Diagnostics.Debug.WriteLine(r);
            }
        }

        private Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
        {
            return assembly.GetTypes().Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
        }

The integer r returns 0 so, as explained in the documentation, no table is created. Is there any way to return a System.Type object to make it work? Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire