I'm trying to make one function that can take an object as a parameter
public static List<T> Get_DataList_DataFromSystem<T>(object DataNeeded, string BaseTypeString)
{
Type baseType = DataNeeded.GetType();
SQliteConnector.GetInstance.conn.Table<baseType>();
}
using SQliteConnector.GetInstance.conn.Table(); i want to able to use the parameter DataNeeded that is passed into the function.
SQliteConnector.GetInstance gets an instance of the (SQLiteConnection( new SQLitePlatformWinRT(), path );)
SQliteConnector.GetInstance.conn.Table(); requires a class to be passed in
Generic methods require the type to be known at compile time, whereas GetType()
is executed at runtime.
This is what you're after:
public static List<T> Get_DataList_DataFromSystem<T>(T DataNeeded, string BaseTypeString) where T : class
{
SQliteConnector.GetInstance.conn.Table<T>();
}
The type of DataNeeded
can then be inferred at compile time, based on the type of object that is passed to the method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.