mercredi 1 juillet 2020

How can get value of variable from more than one class with string

i am trying to make table which table can load various data. the data format is class and in class has various variable which format are string, float, and double.

My data format is below. All of data will save into TotalData class

public class TotalData
{
    public List<A> aList;
    public List<B> bList;
}

public class A
{
    public int classA_intA;
    public int classA_intB;
    public float classA_floatA;
    public float classA_floatB;
    public double classA_doubleA;
    public double classA_doubleB;
}

public class B
{
    public int classB_intA;
    public int classB_intB;
    public float classB_floatA;
    public float classB_floatB;
    public double classB_doubleA;
    public double classB_doubleB;
}


After this set up, I want to search specific data by name of class and name of variable.

For example if I want to get classB_doubleB, then i need name of bList as string to search from TotalData and name of classB_doubleB so I can get value of classB_doubleB


public object GetValueFromTotalData(string getDataFromClass, 
                                    string nameOfVariable, 
                                    TotalData data, 
                                    int indexOfList) 
{
    //The string getDataFromClass selects a list to find the variable.

    //The string nameOfVariable selects variable which in selected class

    //indexofList is for choose index of aList or bList
    return value;
}

I hope someone can figure out my problem. thank you. :)





Aucun commentaire:

Enregistrer un commentaire