你好,我需要获取两个集合作为XpCollections,但是"cMemberInfo.GetValue(this)“给我的类型是"DevExpress.Xpo.XPCollection`1”,有没有可能以某种方式将它转换为DevExpress.Xpo.XPCollection?
XPCollection cColl1 = cMemberInfo.GetValue(this) as XPCollection;
XPCollection cColl2 = cMemberInfo.GetValue(cObject) as XPCollection;由于不转换类型,因此两个cColl都为空
使用这些集合的地方有完整的代码部分
foreach (XPMemberInfo cMemberInfo in ClassInfo.CollectionProperties)
{
XPCollection cColl1 = cMemberInfo.GetValue(this) as XPCollection;
XPCollection cColl2 = cMemberInfo.GetValue(cObject) as XPCollection;
if (cColl1 == null || cColl2 == null) { Debug.Assert(false); return false; }
if (cColl1.Count != cColl2.Count) { return false; }
for (int i = 0; i < cColl1.Count; ++i)
{
XPOBase cObj1 = cColl1[i] as XPOBase;
XPOBase cObj2 = cColl2[i] as XPOBase;
bRet &= cObj1.IsDataEqual(cObj2);
}
}如果在XPCollection中使用XPBaseCollection,则不能声明cColl1i或cColl2i
发布于 2012-08-03 17:05:56
GetValue返回一个泛型XPCollection<T>,其中T是集合对象的类型。
XPCollection<MyType> cColl1 = cMemberInfo.GetValue(this) as XPBaseCollection<MyType>;
XPCollection<MyOtherType> cColl2 = cMemberInfo.GetValue(cObject) as XPBaseCollection<MyOtherType>;或者,您可以改用XPBaseCollection:
XPBaseCollection cColl1 = cMemberInfo.GetValue(this) as XPBaseCollection;
XPBaseCollection cColl2 = cMemberInfo.GetValue(cObject) as XPBaseCollection;https://stackoverflow.com/questions/11792059
复制相似问题