【发布时间】:2015-08-05 23:07:49
【问题描述】:
我正在尝试做一些新的事情并得到了这个错误,我在 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);
}
问题是当我将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;
}
}
我收到以下错误:
必须是具有公共无参数构造函数的非抽象类型
谁能帮我找出我的代码有什么问题?
【问题讨论】:
-
您作为 T 传递的类型是什么?它是具有默认构造函数的具体类吗?