我有一套類和接口有一個相對簡單的層次結構,但有東西繼承,然後有一個接受基類的變量工作不正常。我認爲問題在於我的動態類型必須爲where : class
而不是where : IEntity
,因爲這些類型用於我無法更改的功能。C#將派生類分配給基類變量與泛型
public interface IB<X, Y>
where X : class, IEntity
where Y : class, IEntity
{
...
}
public abstract class A
{
...
}
public abstract class B<X, Y> : A, IB<X, Y>
where X : class, IEntity
where Y : class, IEntity
{
...
}
public interface IEntity
{
...
}
public class Entity1 : IEntity
{
...
}
public class Entity2 : IEntity
{
...
}
public class C : B<Entity1, Entity2>, IB<Entity1, Entity2>
{
...
}
,然後嘗試使用所有這一切在功能...
C c = new C();
IB<IEntity, IEntity> ib = c;
無法implicityly或明確地施放此。
我該如何得到這個工作?
也許總是要提一提,這需要C#4(和.NET 4.0?) – Davy8
像魅力一樣工作!完善。謝謝謝謝! – smdrager