内部接口? [英] Internal interfaces?

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

问题描述

你好!


我想知道为什么我们被允许将接口定义为内部接口,当所有接口的成员都被实现时在课堂上,是公开的吗?


我知道接口是合同,但为什么你不被允许

也有内部合同,不一定公开揭露会员

?你不允许把一个物体投射到内部界面,

但是我不能让这些成员保持在内部。


它''非常烦人,因为我必须引入额外的抽象类来实现隐藏的界面成员。


内部界面IXml

{

string ToXml();

}


公共类CmsObject:IXml

{

..其他成员/构造函数


public string ToXml(){return null; }

}


......和另一个项目(汇编):


CmsObject o = new CmsObject ();

string s = o.ToXml();


-

venlig hilsen /关于

anders borum

-

Hello!

I was wondering why we''re allowed to define interfaces as internal, when all
the members of the interface, when implemented in a class, are made public?

I know that interfaces serve as contracts, but why wouldn''t you be allowed
to have internal contracts also, not necessarily exposing the members
publicly? You''re not allowed to cast an object to the internal interface,
but I''m unable to keep the members internal.

It''s quite annoying as I''ll have to introduce extra abstract classes to
achieve the hidden interface members.

internal interface IXml
{
string ToXml();
}

public class CmsObject : IXml
{
.. other members / constructors

public string ToXml() { return null; }
}

... and in another project (assembly):

CmsObject o = new CmsObject();
string s = o.ToXml();

--
venlig hilsen / with regards
anders borum
--

推荐答案

只需实现explcitly接口,然后只能访问其成员通过基于inerface的参考,只有你可以访问interace本身才有可能


问候


Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk


nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/< eJ**************@TK2MSFTNGP14.phx.gbl>


您好!


我想知道为什么我们'重新允许将接口定义为内部接口,当所有接口的成员在类中实现时,都公开了吗?


我知道接口作为合同,但为什么你不被允许

也有内部合同,不一定公开会员公开?b $ b?你不允许把一个物体投射到内部界面,

但是我不能让这些成员保持在内部。


它''非常烦人,因为我必须引入额外的抽象类来实现隐藏的界面成员。

Just implement the interface explcitly, then its members are only accessible via an inerface based reference which is only possible if you have access to the interace itself

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<eJ**************@TK2MSFTNGP14.phx.gbl>

Hello!

I was wondering why we''re allowed to define interfaces as internal, when all
the members of the interface, when implemented in a class, are made public?

I know that interfaces serve as contracts, but why wouldn''t you be allowed
to have internal contracts also, not necessarily exposing the members
publicly? You''re not allowed to cast an object to the internal interface,
but I''m unable to keep the members internal.

It''s quite annoying as I''ll have to introduce extra abstract classes to
achieve the hidden interface members.


你好!


我明白你在说什么,但是你能给我一个简短的例子a''la

我提出的那个吗?


谢谢Richard!


-

venlig hilsen /关心

anders borum

-
Hello!

I understand what you''re saying, but could you give me a short example a''la
the one I presented?

Thanks Richard!

--
venlig hilsen / with regards
anders borum
--


我认为他的意思是:


公共类CmsObject:IXml

{

..其他会员/构造商


//更改在这里(添加IXml并公开删除)

string IXml.ToXml(){return null; }

}


" Anders Borum" <一个**** @ sphereworks.dk>在消息中写道

news:eR ************* @ TK2MSFTNGP12.phx.gbl ...
I think he means this:

public class CmsObject : IXml
{
.. other members / constructors

// Change is here (added IXml and removed public)
string IXml.ToXml() { return null; }
}

"Anders Borum" <an****@sphereworks.dk> wrote in message
news:eR*************@TK2MSFTNGP12.phx.gbl...
你好!

我明白你在说什么,但是你能给我一个简短的例子吗?我给你的那个?

谢谢理查德! br />
-
venlig hilsen /问候
anders borum
-
Hello!

I understand what you''re saying, but could you give me a short example
a''la
the one I presented?

Thanks Richard!

--
venlig hilsen / with regards
anders borum
--



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

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