Querying by type in DB4O
.net, argument-passing, c#, db4o, function
Solution
There are two ways. The first is to explicitly use the Type type.
public static void PrintAllPilots(Type type, string pathToDb)
{
...
IObjectSet result = db.QueryByExample(type);
}
PrintAllPilots(typeof(SomeType),somePath);
The second is to use generics
public static void PrintAllPilots<T>(string pathToDb)
{
...
IObjectSet result = db.QueryByExample(typeof(T));
}
PrintAllPilots<SomeType>(somePath);
Problem
How do you pass a class type into a function in C#? As I am getting into db4o and C# I wrote the following function after reading the tutorials: ``` public static void PrintAllPilots("CLASS HERE", string pathToDb) { IObjectContainer db = Db4oFactory.OpenFile(pathToDb); IObjectSet result = db.QueryByExample(typeof("CLASS HERE")); db.Close(); ListResult(result); } ```