我有一个接口具有另一个接口的属性。无论如何,只要在使用中引用父接口,就会导出/提供/包含子接口。导出接口
//IBar.cs
namespace bar
{
interface IBar
{
public int BarProp { get; set; }
}
}
//IFoo.cs
namespace foo
{
using bar
interface IFoo
{
public IBar FooProp { get; set; }
}
}
//elsewhere.cs
namespace foo
{
//using bar //without this,
IFoo myFoo = new SomeClassThatImplementsIFoo();
myFoo.FooProp.BarProp //<-- BarProp is inaccessable here
}
在elsewhere.cs,我不得不IFoo的一个参考,但希望能够访问伊巴尔的元素,而无需包括引用和using语句来伊巴尔。无论如何设置IFoo,只要它被引用/包含,它也带来IBAR一起乘坐?类似#include
的方式直接运行C. 如果您说“复制并粘贴IBar到IFoo.cs”,我会忽略你。
我猜测,因为我从来没有看到任何可以做到这一点的东西,答案可能是你不能在C#中做到这一点。
编辑:的文件IBar.cs和IFoo.cs是在单独的组件
编辑:的接口是公开的,不是性能
对不起,我的意思是表明他们在不同的程序集以及不同的文件。 – 2011-01-06 19:48:22