类在使用泛型时不实现接口成员

本文关键字:实现 接口 成员 泛型 | 更新日期: 2023-09-27 18:28:15

我有一个通用接口定义如下:

interface INewRegionBoarding<T> where T: class
{
    bool Create(T objectName);
    bool ValidateData(T objectName);
}

然后,我有一个实现它的类:

public class ESafeActionService<T>: INewRegionBoarding<T>
{
    public bool ValidateData(EsafeActons eSafe)
    {
        if (String.IsNullOrEmpty(eSafe.Corporation)) return false;
        if (String.IsNullOrEmpty(eSafe.Region))
        {
            return false;
        }
        else if (eSafe.Region.Length != 2)
        {
            return false;
        }
        return true;
    }
       public bool Create(EsafeActons eSafe)
       {
           return eSafe.Create(eSafe.Corporation, eSafe.Region, eSafe.PortfolioName);
       }
    }

在构建它时,我有以下错误:

'ESafeActionService<EsafeActions>' does not implement interface member INewRegionBoarding<EsafeActions>.ValidateData(EsafeActions)'

这是ESafeAction类的定义:

公开课EsafeActons{

private string corporation;
private string region;
private string portfolioName;
public EsafeActons(string corporation, string region, string portfolioName)
{
    this.corporation = corporation;
    this.region = region;
    this.portfolioName = portfolioName;
}

public string Corporation
{
    get { return this.corporation; }
    set { this.corporation = value; }
}
public string Region
{
    get{return this.corporation;}
    set { this.region = value; }
}
public string PortfolioName
{
    get { return this.corporation; }
    set { this.portfolioName = value; }
}
public bool Create(string corporation, string region, string portfolioName)
{
    //call stored proc
    return true;
}

}

我真的不确定我做错了什么。

感谢

类在使用泛型时不实现接口成员

我真的不确定我做错了什么

您保持类的通用性,但使用特定类型实现接口。将类定义更改为:

public class ESafeActionService: INewRegionBoarding<EsafeActons>
{