示例#1
0
        private void AddNewObjectToCollectionSource(CollectionSourceBase currentCollectionSource, object newObject, XPObjectSpace objectSpace)
        {
            var newObjectTypeInfo = XafTypesInfo.Instance.FindTypeInfo(newObject.GetType());

            if ((currentCollectionSource == null) ||
                !currentCollectionSource.ObjectTypeInfo.IsAssignableFrom(newObjectTypeInfo))
            {
                return;
            }

            if (objectSpace == currentCollectionSource.ObjectSpace)
            {
                currentCollectionSource.Add(newObject);
            }
            else
            {
                var propertyCollectionSource = (currentCollectionSource as PropertyCollectionSource);
                if ((propertyCollectionSource != null) && (propertyCollectionSource.MasterObject != null))
                {
                    Object      collectionOwner;
                    IMemberInfo memberInfo = null;
                    if (propertyCollectionSource.MemberInfo.GetPath().Count > 1)
                    {
                        collectionOwner = ImportUtils.GetCollectionOwner(propertyCollectionSource.MasterObject,
                                                                         propertyCollectionSource.MemberInfo);
                        if (collectionOwner != null)
                        {
                            memberInfo =
                                XafTypesInfo.Instance.FindTypeInfo(collectionOwner.GetType())
                                .FindMember(propertyCollectionSource.MemberInfo.LastMember.Name);
                        }
                    }
                    else
                    {
                        collectionOwner = propertyCollectionSource.MasterObject;
                        memberInfo      = propertyCollectionSource.MemberInfo;
                    }
                    if ((collectionOwner != null) &&
                        XafTypesInfo.Instance.FindTypeInfo(collectionOwner.GetType()).IsPersistent)
                    {
                        var collectionSource = _application.CreatePropertyCollectionSource(objectSpace, null,
                                                                                           objectSpace.GetObject(collectionOwner), memberInfo, "", CollectionSourceMode.Normal);
                        collectionSource.Add(newObject);
                    }
                }
            }
        }
示例#2
0
 ListView CreateListView(IModelListView childModelListView, IModelMember relationModelMember, XafApplication application) {
     var propertyCollectionSource = application.CreatePropertyCollectionSource(_objectSpace, childModelListView.ModelClass.TypeInfo.Type, null, relationModelMember.MemberInfo, childModelListView.Id);
     return application.CreateListView(childModelListView, propertyCollectionSource, false);
 }
示例#3
0
        ListView CreateListView(IModelListView childModelListView, IModelMember relationModelMember, XafApplication application)
        {
            var propertyCollectionSource = application.CreatePropertyCollectionSource(_objectSpace, childModelListView.ModelClass.TypeInfo.Type, null, relationModelMember.MemberInfo, childModelListView.Id);

            return(application.CreateListView(childModelListView, propertyCollectionSource, false));
        }