1

我有它的签名看起来像的方法

public object LoadCache(string cacheName,Type returnType)

并且从这个方法中调用另一个方法,像这样的签名

 BBCacheProvider.BbCacheProvider.GetCache<T>(string cacheName);

有没有办法在方法中将 returnType 参数作为 T 发送?

我相信没有办法做到这一点!但必须有办法解决它!

4

1 回答 1

0

我在这里找到了一个类似的解决方案 ,我确实根据需要对其进行了更改。所以反思是英雄。

public void ClientCacheLoadRerquest(Type tType, string key)
    {
        MethodInfo method = this.GetType().GetMethod("GetCache");
        MethodInfo closedMethod = method.MakeGenericMethod(tType);
        closedMethod.Invoke(this, new object[] { key });
    }
于 2013-10-03T06:06:32.903 回答