我有通用静态类:
public static class IsolatedStorageCacheManager<BagType>
{
}
和方法:
public static BagType Retrieve()
{
BagType obj = default(BagType);
try
{
IsolatedStorageFile appStore = IsolatedStorageFile.GetUserStoreForApplication();
string fileName = string.Format(CultureInfo.InvariantCulture, "{0}.xml", obj.GetType().Name);
if (appStore.FileExists(fileName))
{
using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(fileName, FileMode.Open, appStore))
{
using (StreamReader sr = new StreamReader(isoStream))
{
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(obj.GetType());
obj = (BagType)x.Deserialize(sr);
}
}
}
}
catch (Exception ex)
{
log.Error(ex.Message);
}
return obj;
}
如何在 Retrive 方法中将特定类型作为 BagType 发送?我尝试使用反射但没有结果;/