0

您好,我需要将两个集合作为 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 都是 null

有使用这些集合的代码的完整部分

            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,我无法声明 cColl1[i] 或 cColl2[i]

4

1 回答 1

0

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;
于 2012-08-03T09:05:55.500 回答