2010-03-25 53 views
0

我試圖創建一個基於關的從我的核心對象模型接口,WCF數據模型,但我有一些在我的核心數據的關聯對象模型合同

目前我有這個麻煩當我定義接口IA我收到編譯器錯誤話說不會實現所有IA的模型。然而

public class A : IA { 
     public string name { /* ... */ } 
     public EntitySet<B> children { /* ... */ } 
} 
public class B : IB { 
     public string name { /* ... */ } 
} 

。這裏是接口

public interface IA<BType> where BType: IB { 
    string name {get; set;} 
    IEnumerable<Btype> children {get;} 
} 

爲什麼不能將A的實例作爲IA引用傳遞給定這些類和接口定義?

回答

1

編譯錯誤,因爲public EntitySet<B> children不執行IEnumerable<Btype> children {get;}(.NET < 4.0版本不支持協\逆變)

+0

這並不完全正確。 .NET和2.0中的泛型一起被添加到了.NET和協變中。它在C#中直到4.0才被支持,但.NET支持它很好,例如Eiffel.NET使用它。 – 2010-03-25 18:20:33

+0

所以你說這將在.net 4.0中編譯? – 2010-03-26 14:35:05