【发布时间】:2011-01-06 18:55:42
【问题描述】:
我有一个具有另一个接口属性的接口。每当在使用中引用父接口时,是否有导出/提供/包含子接口的方法。
//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
}
在 else.cs 中,我有对 IFoo 的引用,但希望能够访问 IBar 的元素,而不必包含对 IBar 的引用和 using 语句。无论如何设置 IFoo 以便每当它被引用/包含时,它也会带来 IBar 吗?类似于#includes 在直接 C 中的工作方式。
如果你说“将 IBar 复制并粘贴到 IFoo.cs 中”,我会忽略你。
我猜是因为我从未见过任何可以做到这一点的东西,答案可能是你不能在 C# 中做到这一点。
编辑:文件 IBar.cs 和 IFoo.cs 位于单独的程序集中
编辑:接口是公共的,而不是属性
【问题讨论】: