如何从T参数调用接口方法?

Jos*_*rín -3 c#

基本上,我要做的是在类中调用接口方法,如下所示:

public class MongoConnection<T> where T: IMongoEntity
{
    public MongoConnection()
    {
        string connectionString = Configuration.Default.ConnectionString;

        var mongoClient = new MongoClient(connectionString);
        var server = mongoClient.GetServer();

        string DBName= "DBName";

        var DB = server.GetDatabase(DBName);

        MongoCollection collection = DB.GetCollection<T>(T.MyInterfaceMethod());
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在做的原因

MongoCollection collection = BD.GetCollection<T>(T.GetCollectionName());
Run Code Online (Sandbox Code Playgroud)

代替

MongoCollection collection = BD.GetCollection<T>(typeof(T).Name);
Run Code Online (Sandbox Code Playgroud)

因为不会有这种类型的一个集合,所以会有多个具有相同结构的集合.

提前感谢您的回答.

Dan*_*ite 6

在C#中没有静态接口这样的东西.