【发布时间】:2014-03-05 11:50:00
【问题描述】:
我有一个方法,其签名如下所示:
public IList<T> GetReferenceData<T>(TransactionManager transactionManager = null)
{
IList<T> collection;
var cacheData = DataCacheManager.Instance.GetCacheItem(typeof(T).Name);
if (cacheData != null)
{
collection = (IList<T>)cacheData;
}
else
{
collection = this.GetReferenceDataNoCache<T>(transactionManager);
DataCacheManager.Instance.AddCacheItem(typeof(T).Name, collection);
}
return collection;
}
我有另一种方法允许我传入一个字符串,该方法将该字符串转换为适当的类型。然后我想调用上面的方法。
public IList GetReferenceDataByType(string referenceType)
{
// this works and returns the appropriate type correctly
var type = this.GetEntity(referenceType);
// now I'm stuck
return this.GetReferenceData<?>();
}
问号用什么代替?
【问题讨论】:
-
如果你需要这个方法,那可能有问题。
-
@TimSchmelter 这不是问题所在。他已经有了类型。他想得到一个基于可变类型参数的完全解析的泛型方法
-
你能发帖
GetReferenceData<T>body 吗? -
@TimSchmelter 请求来自 SOA Web 服务。它不能传递内部类型。它实际上是在传递一个枚举。我只是简化了代码以使其成为一个字符串,这样我就不需要开始发布枚举了。