-1

我有通用静态类:

 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 发送?我尝试使用反射但没有结果;/

4

1 回答 1

1

我不太确定你想要什么,但这有帮助吗?

public static class IsolatedStorageCacheManager<BagType>
{
    public static Type Retrieve()
    {
        return typeof(BagType);
    }
} 
于 2012-09-23T00:43:22.133 回答