Abstract class cast operator

眉间皱痕 提交于 2019-12-11 16:54:44

问题


Poco items are wrapped.

abstract class AbstractPocoUI<T> {
    protected T PocoItem;
}

class PocoA {

}
class PocoAUI:AbstractPocoUI<PocoA> {

}

I want to do something like this

var c = new ObservableCollection<PocoAUI>(collectionOfTypePocoA.Cast<PocoAUI>());

How can i override cast operator in abstract class? What should i do in AbstractPocoUI to get for example PocoAUI with PocoA in PocoItem field ? Thanks.


回答1:


You can implement IConvertible interface or create a TypeConverter but casting cannot be overriden.


Have a look at Implicit Operator overloading here.



来源:https://stackoverflow.com/questions/5990663/abstract-class-cast-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!