dynamic - Getting a dynamically typed ServiceStack.redis client in C# -


i new c# whole , wondering how achieve functionality described below. not compiling @ indicated lines. code is:

iterate through each kvp, query db using keystring table name return list

var dbcon = dbconnectionfactory.opendbconnection(); dictionary<string, type> ibetdic = getfromsomewhere(); foreach (keyvaluepair<string, type> entry in ibetdic)     {         type type = entry.value;         var typedredisclient = redis.gettypedclient<type>();/*not compiling here*/         string sql = "use ibet select * " + entry.key;         var itemlist = dbcon.sqllist<type>(sql);/*not compiling here*/         foreach (var tablerow in itemlist )         {             //store redistypedclient         }     } 

closest thing answer have found means have pass in type rather able access through dictionary wanting above:

public void getandstoreintkey<t>(string tablename) t : ihasid<int>     {         var dbcon = dbconnectionfactory.opendbconnection();         string sql = "use ibet select * " + tablename;         var items = dbcon.sqllist<t>(sql);         var typedredisclient = redis.as<t>();          foreach (t item in items)         {             typedredisclient.setentry(urnid.createwithparts<t>(new string[] {item.id + ""}), item);         }     } 

usage :

 getandstoreintkey<sport>("sport"); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -