[英]Must be a non abstract type with public parameterless constructor c#
I'm trying to do something new and got this error, I have an interface in c# 我正在尝试做新的事情并遇到此错误,我在C#中有一个接口
public interface IRepository<TSource>: IDisposable where TSource: class
{
TSource GetById(long id);
List<TSource> GetAll();
bool InsertOrUpdate(TSource source);
bool Delete(long id);
VM.RetornoGenerico<TSource> Upload(long id);
}
The problem is when I pass TSource
to my RetornoGenerico
Class 问题是当我将
TSource
传递给RetornoGenerico
类时
public class RetornoGenerico<T> where T : new()
{
public T Result { get; set; }
public bool Success { get; set; }
public string ErrorMsg { get; set; }
public string IdError { get; set; }
public RetornoGenerico()
{
Result: new T();
Success = false;
}
public static RetornoGenerico<T> CloneError<TU>(RetornoGenerico<TU> resposta) where TU : new()
{
var retorno = new RetornoGenerico<T>()
{
Success = resposta.Success,
Result = new T(),
ErrorMsg = resposta.ErrorMsg,
IdError = resposta.IdError
};
return retorno;
}
}
I get the following error: 我收到以下错误:
Must be a non abstract type with public parameterless constructor
必须是具有公共无参数构造函数的非抽象类型
Can someone help me find what is wrong with my code? 有人可以帮我找到我的代码有什么问题吗?
由于您的类具有where T : new()
,并且您正在将TSource
传递给该类,因此TSource
必须具有相同的约束。
public interface IRepository<TSource>: IDisposable where TSource: class, new()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.