c# - Generics T based parser for different properties within a string -


i have feed coming has different properties serialized comma separated values

feed = "[{"high", "[235.76, 235.96, 235.97]"},           {"low", "[235.76, 235.96, 235.97'"},           {"date", "[20170410-10:21:34, 20170410-10:31:34, 20170410-10:43:34, 20170410-10:59:34]" }  .....         ]" 

i have business need create entity out of containing different properties each of high /low /date etc. "high" , low of double whereas date of datetime type. splitting string following each tag , parsing each value corresponding property.

however since property's datatype differ, require parse function each type.

private void getfeeddata(string[] data, list<int> field)     {         (int = 0; < data.length; i++)         {             **int fieldvalue = int.parse(data[i]);**             field.add(fieldvalue);         }     } 

i have ended different functions, 1 specific each datatype, differing in parsing of fieldvalue

i want this, doesn't seem supported.

private void getfeeddata<t>(string[] data, list<t> field) t: struct     {         (int = 0; < data.length; i++)         {             t fieldvalue = (t)(data[i]);             field.add(fieldvalue);         }     } 

this single method types, lot easier. not sure how achieve this.. please help

try this, think example not syntactically correct.

private ilist<t> getfeeddata<t>(string[] data)  {     list<t> field = new list<t>();      (int = 0; < data.length; i++)     {         t fieldvalue = (t)(convert.changetype(data[i], typeof(t)));         field.add(fieldvalue);     }      return field; } 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -