2

If project A has an interface A, and project B has a class B that implements interface A, then project B needs a reference to project A.

In project B:

public class B : A
{
    void A.MethodA()
    {
    }
}

But if project C uses class B, without ever using it as the interface A (so no code that calls A's method on an instance of B or casts an instance of B to A), then it must still reference project A. Even if project B explicitly implements interface A (as the example code above does).

In project C:

public class C
{
    public C()
    {
       var b = new B(); 
    }
}

The result is:

The type 'A' is defined in an assembly that is not referenced. You must add a reference to assembly 'A, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.

Why is that?

4

1 回答 1

0

这可能是因为所有 .Net 都可以通过反射访问,因此所有内容都必须可供反射查询查询。

如果在项目 C 中不可用,你将如何将类转换为直接实现它的接口?

于 2013-09-17T15:13:40.533 回答