0

保存对象时,出现以下错误:

must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'ServiceStack.Redis.RedisClient.Store<T>(T)


RedisClass.GetInstance().Store(msg); // Error here
RedisClass.GetInstance().Save();

由于这是第三方的课程,我无法对其进行编辑。如何保存这个对象?

4

2 回答 2

0

该错误是由 IBasicPersistenceProvider.Store<T>() 具有 new() 通用约束引起的。相反,请尝试使用 IBasicPersistenceProvider<T>.Store():

RedisClass.GetInstance().As<ThirdPartyClass>().Store(msg);
于 2013-09-13T07:20:34.580 回答
0

您能否围绕第三方对象创建一个包装器以调用其构造函数,然后存储该包装器?

例如

public class MyWrapper
{
    public ThirdPartyObject ThirdPartyInstance { get; set; }

    public MyWrapper()
    {
        ThirdPartyInstance = new ThirdPartyObject("Constructors");
    }
}
于 2013-07-22T03:01:59.690 回答