vendredi 29 mai 2015

Design Pattern for list of Multiple data type

I have data set like below.

Name     |  Type   | OptionType   | Value
--------------------------------------------
Count    | int     | null         | 20
volume   | double  | null         | 10.2
customer | string  | null         | tim
direction| option  | Left, Right  | Left
shape    | option  | rect, circle | rect
…        |   …     | …            | …

(not only 5. so many data set)

What is the best design pattern or data structure to handle data set ?


I try think that below…

Dictionary <name, object> dataDictionary;

// add
dataDictionary.Add("count", (int)20);
dataDictionary.Add("volume", (double)10.2);
dataDictionary.Add("customer", "tim");
dataDictionary.Add("direction", enumDirection.Left);
dataDictionary.Add("shape", enumShape.Rect);

// get - **I have to know data type….**
int count = (int)dataDictionary["count"];
double volume = (double)dataDictionary["volume"] ;
string customer = (string)dataDictionary["customer"];
enumDirection eDirection = (enumDirection)dataDictionary["direction"];

Is anything better?

Aucun commentaire:

Enregistrer un commentaire