C#中的冲突接口实现

时间:2014-01-11 07:50:17

标签: c# asp.net asp.net-mvc asp.net-mvc-4 c#-4.0

我想实现Interface方法,在我的类中实现所有方法之后,我有一个错误,请实现所有方法,我的界面是:

public interface IAccountRepository
{
    Task<IAccount> AuthenticateAsync(string username, string password);
    Task<IAccount> RegisterAsync(string username, string password,AccountType accountType);
}

我想要实现的课程是:

public class AccountRepository : IAccountRepository
{
    public Task<IAccount> AuthenticateAsync(string username, string password)
    {
        ISession session = null;
        Task<Mabna.AccountsSDK.IAccount> objAccount;
        var objAccountsSdk = new Mabna.AccountsSDK.Client(session);
        objAccountsSdk.AccountManager.AuthenticateAsync(username, password);
        return null;
    }

    public Task<IAccount> RegisterAsync(string username, string password, AccountType accounttype)
    {
        ISession session = null;
        Task<Mabna.AccountsSDK.IAccount> objAccount;
        var objAccountsSdk = new Mabna.AccountsSDK.Client(session);
        objAccountsSdk.AccountManager.RegisterAsync(username, password,accounttype);
        return null;
    }
}

3 个答案:

答案 0 :(得分:0)

(前言:我认为这通常不会导致实现错误),您的accountType变量在您的界面和类上有所不同。你的班级有accounttype 注意t不是班级的资本

在外壳之外,其他一切看起来都是合法的。您是否100%确定在此界面上收到此错误而不是IAccount或ISession?

作为旁注,当你显然总是返回null时,为什么你的方法的返回类型为Task<IAccount>?为什么不制作这些void方法?

答案 1 :(得分:0)

似乎没有实现RegisterAsync 你确实实现了RegisterAsync1

答案 2 :(得分:0)

试试这个

public interface IAccountRepository
{
    Task AuthenticateAsync(string username, string password);
    Task RegisterAsync(string username, string password,AccountType accountType);
}

由于您没有返回值使用任务:

public class AccountRepository : IAccountRepository
{
    public async Task AuthenticateAsync(string username, string password)
    {
        ISession session = null;
        Task<Mabna.AccountsSDK.IAccount> objAccount;
        var objAccountsSdk = new Mabna.AccountsSDK.Client(session);
        await objAccountsSdk.AccountManager.AuthenticateAsync(username, password);
    }

    public async Task RegisterAsync(string username, string password, AccountType accounttype)
    {
        ISession session = null;
        Task<Mabna.AccountsSDK.IAccount> objAccount;
        var objAccountsSdk = new Mabna.AccountsSDK.Client(session);
        await objAccountsSdk.AccountManager.RegisterAsync(username, password,accounttype);
    }
}