【发布时间】:2012-01-06 19:35:10
【问题描述】:
我有一个包含特殊集合的泛型类。此集合的实例作为对象传递给方法。现在我必须调用通用类的方法之一。我看到的问题是我不知道集合中的项目属于哪种类型,因此我无法在使用该属性之前进行转换。
public class MyGenericCollection<T>: ReadOnlyObservableCollection<T>
{
public bool MyProperty
{
get
{
// do some stuff and return
}
}
}
public bool ProblematicMethod(object argument)
{
MyGenericCollection impossibleCast = (MyGenericCollection) argument;
return impossibleCast.MyProperty;
}
有没有办法解决这个问题?
【问题讨论】:
标签: c# generics methods casting