Forum Cross Platform with Xamarin

Reflection on SQLite table

I have a sql lite class

namespace MyApp
{
    [Table("mydata_table")]
    public class MyData
    {
        [PrimaryKey, AutoIncrement, Column("_id")]
        public int ID { get; set; }

        [Unique, NotNull]
        public Guid GUID { get; set; }

        [MaxLength(256), NotNull]
        public string Name { get; set; }
    }
}

and I am trying to extract the custom attributes and members via reflection.

MyData md = new MyData
{
    GUID = new Guid(),
    ID = 14,
    Name = "test"
};
TypeInfo typeInfo = md.GetType().GetTypeInfo();
TableAttribute table = (TableAttribute)typeInfo.GetCustomAttribute(typeof(TableAttribute));

But I keep getting the following exception ... Exception thrown: 'System.IO.FileLoadException' in System.Private.CoreLib.ni.dll

I need to extract the table name, and for each public member, the member name, value and also it's properties (like PrimaryKey, NotNull, etc)

Sign In or Register to comment.