实施2接口与'同名'属性 [英] Implementing 2 Interfaces with 'Same Name' Properties

查看:160
本文介绍了实施2接口与'同名'属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个合理的(也许简单吗?)的情况下,但你会怎么做以下内容:

This seems like a reasonable (and maybe simple?) scenario, but how would you do the following:

可以说我有2接口:

Interface ISimpleInterface
    string ErrorMsg { get; } 
End Interface

Interface IExtendedInterface
    string ErrorMsg { get; set; }    
    string SomeOtherProperty { get; set; }
End Interface



我想一个类来实现两个接口:

I want a class to implement both interfaces:

Public Class Foo Implements ISimpleInterface, IExtendedInterface


$ b ?$ b

我如何在类中定义的ERRORMSG属性给出每个接口都有一个不同的访问级别

How do I define the ErrorMsg property in the class given that each interface has a different access level?

下面是我的情况你想知道:我使用的是伪MVC arhitecture,那里的用户控件公开扩展接口,它的控制器写一个用户控件,并公开了简单的界面控件的消费者。

Here is my scenario in case you are wondering: I am writing a UserControl using a psuedo MVC arhitecture, where the UserControl exposes the extended interface to it's Controller, and exposes the Simple interface to the Consumers of the control.

通过顺便说一下,在VB.NET实现这个(任何建议synatx在VB中,将不胜感激)。

By the way, implementing this in VB.NET (any suggested synatx in vb would be appreciated).

推荐答案

您可以实现的一个他们或与显式接口实现两个接口,所以编译器知道哪些ERRORMSG财产属于哪个接口

You can implement one of them or both interfaces with an 'explicit interface' implementation, so the compiler knows which ErrorMsg property belongs to which interface.

要做到这一点简单地写:ISimpleInterface(对于C#) 。您的类名称后,然后点击ISimpleInterface并选择实现显式接口

To do this simply write :ISimpleInterface (for C#) after your class name and then click on ISimpleInterface and select implement explicit interface.

点击此处了解详情:的 http://msdn.microsoft.com/en-us/library/aa288461(VS.71)的.aspx

More information here: http://msdn.microsoft.com/en-us/library/aa288461(VS.71).aspx

这篇关于实施2接口与'同名'属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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