无法修复接口实现错误

时间:2015-10-16 11:10:44

标签: c#

这是我收到的错误消息:

  

' BusinessLogicLayer'没有实现接口成员' IBusinessLogicLayer.ColorSource_GetByID(Guid)'。 ' BusinessLogicLayer.ColorSource_GetByID(GUID)'无法实施IBusinessLogicLayer.ColorSource_GetByID(Guid)'因为它没有匹配的返回类型' ColorIndex'。

BLL中导致错误的特定区域的代码是:

namespace TartanGenerator.BLL
{
    public interface IBusinessLogicLayer
    {
        ColorIndex ColorSource_GetByID(Guid ColorSourceID);
    }

    public class BusinessLogicLayer : IBusinessLogicLayer
    {
        private readonly IColorSourceRepository _IColorSourceRepository;

        public BusinessLogicLayer()
        {
            _IColorSourceRepository = new ColorSourceRepository();
        }

        public BusinessLogicLayer(IColorSourceRepository ColorSourceRepository)
        {
            _IColorSourceRepository = ColorSourceRepository;
        }

        public ColorSource ColorSource_GetByID(Guid ColorSourceID)
        {
// This is where I believe the error is coming from 
            return _IColorSourceRepository.GetSingle(cs => cs.RecordID.Equals(ColorSourceID));
        }
    }
}

我不知道提供哪些其他源代码是有帮助的,这是我第一次尝试这种方式来做EF。

编辑1

我搜索了我的整个解决方案,这两种类型在同一方法中唯一的位置是EDMX文件。否则两人永远不会见面。

2 个答案:

答案 0 :(得分:0)

像这样更改你的功能:

            ColorIndex ColorSource_GetByID(Guid ColorSourceID)
            {
                // This is where I believe the error is coming from 
                return _IColorSourceRepository.GetSingle(cs => cs.RecordID.Equals(ColorSourceID));
            }

在类中实现接口时,右键单击visual studio中的接口名称,您将看到名为implement interface的选项。这将为您创建没有签名不匹配的接口实现。

 public class BusinessLogicLayer : IBusinessLogicLayer

右键单击IBusinessLogicLayer以获取该选项。

答案 1 :(得分:0)

问题是您的现有方法具有不正确的返回类型以匹配接口方法。由于返回类型不是方法签名的一部分,因此您无法添加仅在返回类型方面不同的其他方法。

你可以做的是明确地实现接口方法。

ColorIndex IBusinessLogicLayer.ColorSource_GetByID(Guid ColorSourceID) {
    var colorSource = ColorSource_GetByID(ColorSourceID);
    var colorIndex = // Do something to convert a color-source to a color-index.
    return colorIndex;
}