保存对象时,出现以下错误:
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();
由于这是第三方的课程,我无法编辑。如何保存此对象?
答案 0 :(得分:0)
你能围绕第三方对象创建一个包装器来调用它的构造函数,然后存储包装器吗?
E.g。
public class MyWrapper
{
public ThirdPartyObject ThirdPartyInstance { get; set; }
public MyWrapper()
{
ThirdPartyInstance = new ThirdPartyObject("Constructors");
}
}
答案 1 :(得分:0)
错误是由IBasicPersistenceProvider.Store&lt; T&gt;()具有new()泛型约束引起的。相反,尝试使用IBasicPersistenceProvider&lt; T&gt; .Store():
RedisClass.GetInstance().As<ThirdPartyClass>().Store(msg);