xamarin.ios - Xamarin PCL and sqlite.net -


i have need, in pcl xamarin, pass function type, used perform query. code tried use this:

public object sqlleggi(string sql, type mytype){  sqlitecommand cmd = db.createcommand(sql);  var results = cmd.executequery< mytype > (); [..] } 

but not work, give me error:

the type or namespace 'mytype' not found. 

does know if possible such thing?

thank much

the mytype in 2 statements play different roles:

public object sqlleggi(string sql, type mytype){ 

here, mytype type object, referencing instance of type class.

var results = cmd.executequery< mytype > (); 

here, mytype type identifier, syntactic construct referring specific type, 1 named mytype in case.

now, there 2 ways handle specific problem:

  1. look @ object type in cmd , see if there overload or alternative method executequery takes type object parameter instead
  2. make method generic don't have type object begin with.

the first case presumably written in way:

var results = cmd.executequery(mytype); 

the second this:

public mytype sqlleggi<mytype>(string sql{     sqlitecommand cmd = db.createcommand(sql);     var results = cmd.executequery< mytype > ();     [..] } 

note that:

  1. i made method return mytype instead of object
  2. mytype specified generic parameter method: sqlleggi<mytype>

naming convention in case dictate generic type parameter named t or beginning t here advice:

public t sqlleggi<t>(string sql{     sqlitecommand cmd = db.createcommand(sql);     var results = cmd.executequery<t>();     [..] } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -