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:
- look @ object type in
cmd
, see if there overload or alternative methodexecutequery
takestype
object parameter instead - 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:
- i made method return
mytype
instead ofobject
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
Post a Comment