我有一个自定义类 Customer 并在另一个类中返回一个基于来自 LiteDB 的 LiteCollection 的列表,该列表使用签名中的 Customer 类进行典型化。我想知道的是是否可以创建一个动态选择哪个类使用类型的方法,这意味着如果我可以将 LiteCollection 的类类型作为参数传递,以便在我调用该方法时返回。
代码如下:
public static LiteCollection<Customer> GetCustomers()
{
var collection = ConnectToDB().GetCollection<Customer>("customers");
return collection;
}