简体   繁体   English

必须是具有公共无参数构造函数c#的非抽象类型

[英]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.

相关问题 必须是具有公共无参数构造函数的非抽象类型 - Must be a non abstract type with public parameterless constructor 'MvxWpfSetup<app> ' 必须是具有公共无参数构造函数的非抽象类型</app> - 'MvxWpfSetup<App>' must be a non-abstract type with a public parameterless constructor 错误:“ T”必须是具有公共无参数构造函数的非抽象类型 - Error: 'T' must be a non-abstract type with a public parameterless constructor 必须是具有公共无参数构造函数的非抽象类型 .net 核心 - must be a non-abstract type with a public parameterless constructor .net Core 必须是非抽象类型,并且在Redis中具有公共无参数构造函数 - must be a non-abstract type with a public parameterless constructor in redis T必须是具有公共无参数构造函数的非抽象类型,以便在泛型类型或方法中将其用作参数“TModel” - T must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'TModel' in the generic type or method 类映射错误:“ T”必须是具有公共无参数构造函数的非抽象类型 - Class Mapping Error: 'T' must be a non-abstract type with a public parameterless constructor 通用 Class 加载程序:“T”必须是具有公共无参数构造函数的非抽象类型 - Generic Class Loader: 'T' must be a non-abstract type with a public parameterless constructor 错误:'T'必须是具有公共无参数构造函数的非抽象类型才能将其用作参数'T' - Error: 'T' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' “ MyObject []”必须是具有公共无参数构造函数的非抽象类型,才能将其用作参数“ T” - 'MyObject[]' must be a non-abstract type with a public parameterless constructor to use it as parameter 'T'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM