vendredi 16 septembre 2016

Get objects whose fields are marked with attributes

guys, i'm writing now something like 'databse system' (orm?) with Unity3D using MySQL. I've come up with a structure for this system so that different entities don't know about existence of my database and they 'live their lives'.

So i've got now one problem.

For instance:

We have following class, just an example:

public class Planet
{
    [Key("planets")]
    [Table("planets","name")]
    public string name;

    [Table("planets", "temperature")]
    public string temperature;
}

Something like this. And We also have remote singleton table object called 'Table':

class Table
{
    public string tableName = "planets";
    public static List<Planet> observables = new List<Planet>();

    public string[,] data;
    public string[] columns;

    public Table()
    {
        columns = new string[] {"name", "temperature"};
        data = new string[,] { { "mars", "venus", "jupiter" },
                               { "-40", "450", "20000" } };
    }

   //finding objcets logic goes here
}

I know how to handle all entitie's fields marked with attributes but the only thing i have to obtain is possibility to receive all my objects with fields decorated by attributes. So how can my Table receive all my Planets instances at any moment not having changed our Planet class.???

I hope i've described problem distinctly and sorry for my horrible English Thanks in advance!





Aucun commentaire:

Enregistrer un commentaire