问题在部分类的接口实现 [英] Problem with interface implementation in partial classes

查看:175
本文介绍了问题在部分类的接口实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于与L2S,自动生成的DataContext问题,使用部分类的问题。我有我的抽象和DataContext的每一个我用的桌子,我实现一个接口的类。在下面的代码中你可以看到我有接口和两个分部类。第一类是只是为了确保类自动生成的DataContext inherets接口。其他自动生成的类确保从接口中的方法来实现。

I have a question regarding a problem with L2S, Autogenerated DataContext and the use of Partial Classes. I have abstracted my datacontext and for every table I use, I'm implementing a class with an interface. In the code below you can see I have the Interface and two partial classes. The first class is just there to make sure the class in the auto-generated datacontext inherets Interface. The other autogenerated class makes sure the method from Interface is implemented.

namespace PartialProject.objects
{

public interface Interface
{
    Interface Instance { get; }
}

//To make sure the autogenerated code inherits Interface
public partial class Class : Interface { }

//This is autogenerated
public partial class Class
{
    public Class Instance
    {
        get
        {
            return this.Instance;
        }
    }
}

}

现在我的问题是,在自动生成的类实现的方法提供了以下错误:
- >属性实例不能从接口PartialProject.objects.Interface'属性。类型应该是'PartialProjects.objects.Interface。 < -

Now my problem is that the method implemented in the autogenerated class gives the following error: -> Property 'Instance' cannot implement property from interface 'PartialProject.objects.Interface'. Type should be 'PartialProjects.objects.Interface'. <-

任何想法,这个错误怎么解决?请记住,我不能编辑在自动生成的代码中任何事情。

Any idea how this error can be resolved? Keep in mind that I can't edit anything in the autogenerated code.

在此先感谢!

推荐答案

You can solve this by implementing the interface explicitely:

您可以通过显式地实现接口解决这个问题b {
公共接口接口
{
接口实例{搞定; }
}

//要确保自动生成的代码继承接口
公共部分类类:接口
{
接口Interface.Instance
{
得到
{
返回实例;
}
}
}

//这是自动生成的
公共部分类类
{
公共类实例
{
得到
{
返回this.Instance;
}
}
}
}

namespace PartialProject.objects { public interface Interface { Interface Instance { get; } } //To make sure the autogenerated code inherits Interface public partial class Class : Interface { Interface Interface.Instance { get { return Instance; } } } //This is autogenerated public partial class Class { public Class Instance { get { return this.Instance; } } } }

这篇关于问题在部分类的接口实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆