interface IModel {}
class MyModel : IModel {}
interface IRepo<T>
where T: IModel { }
class Repo : IRepo<MyModel> { }
//EDIT: A smaller example
IRepo<IModel> repo = new Repo(); // Cannot implicitly convert.. An explicit convertion exists. Missing cast?
// Old example:
/*
The type 'Repo' cannot be used as type parameter 'C' in the generic type or method.
'Castle.MicroKernel.Registration.ComponentRegistration<S>.ImplementedBy<C>()'.
==> There is no implicit reference conversion from 'Repo' to 'IRepo<IModel>'.
*/
container.Register(
Component.For<IRepo<IModel>>()
.ImplementedBy<Repo>());
但是,回購是從IRepo派生的,而MyModel是從IModel派生的。爲什麼這不起作用?派生類型不能隱式轉換爲基本接口
我嘗試添加上回購隱式操作,但它不允許在接口之間轉換..
難道這解決了聯合/禁忌varience東西從C#4(不,我沒有線索我在說什麼:))?
謝謝。猜猜該考慮升級到C#4了。 – simendsjo 2010-11-09 11:51:52