如何将类类型传递给 C# 中的函数?
当我开始学习 db4o 和 C# 时,我在阅读教程后编写了以下函数:
public static void PrintAllPilots("CLASS HERE", string pathToDb)
{
IObjectContainer db = Db4oFactory.OpenFile(pathToDb);
IObjectSet result = db.QueryByExample(typeof("CLASS HERE"));
db.Close();
ListResult(result);
}
最佳答案
有两种方法。第一种是显式使用 Type 类型。
public static void PrintAllPilots(Type type, string pathToDb)
{
...
IObjectSet result = db.QueryByExample(type);
}
PrintAllPilots(typeof(SomeType),somePath);
第二种是使用泛型
public static void PrintAllPilots<T>(string pathToDb)
{
...
IObjectSet result = db.QueryByExample(typeof(T));
}
PrintAllPilots<SomeType>(somePath);
关于c# - 在 DB4O 中按类型查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1027286/