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);
}
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With