コード例 #1
0
        protected virtual void NullifyUniReferences(object obj, IClassMap classMap, IList classMapsWithUniRefs)
        {
            if (classMapsWithUniRefs.Count < 1)
            {
                return;
            }

            IDomainMap         domainMap = this.Context.DomainMap;
            IPersistenceEngine pe        = this.Context.PersistenceEngine;
            IAssemblyManager   am        = this.Context.AssemblyManager;

            foreach (IClassMap classMapWithUniRef in classMapsWithUniRefs)
            {
                Type  classWithUniRef    = am.GetTypeFromClassMap(classMapWithUniRef);
                IList objectsWithUniRefs = pe.GetObjectsOfClassWithUniReferencesToObject(classWithUniRef, obj);
                IList uniRefPropertyMaps = classMapWithUniRef.GetUniDirectionalReferencesTo(classMap, true);
                foreach (object test in objectsWithUniRefs)
                {
                    IClassMap testClassMap = domainMap.MustGetClassMap(test.GetType());
                    NullifyUniReferencesInObject(obj, classMap, test, testClassMap, uniRefPropertyMaps);
                }
            }
        }
コード例 #2
0
        protected virtual void DeserializeClone(object obj, ReadOnlyClone clone)
        {
            IObjectManager   om       = this.Context.ObjectManager;
            IDomainMap       dm       = this.Context.DomainMap;
            IAssemblyManager am       = this.Context.AssemblyManager;
            IClassMap        classMap = dm.MustGetClassMap(obj.GetType());
            IListManager     lm       = this.Context.ListManager;

            foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps())
            {
                if (propertyMap.ReferenceType == ReferenceType.None)
                {
                    if (propertyMap.IsCollection)
                    {
                        IList values = (IList)clone.PropertyValues[propertyMap.Name];
                        IList list   = (IList)om.GetPropertyValue(obj, propertyMap.Name);

                        bool stackMute           = false;
                        IInterceptableList mList = list as IInterceptableList;
                        if (mList != null)
                        {
                            stackMute        = mList.MuteNotify;
                            mList.MuteNotify = true;
                        }
                        list.Clear();

                        foreach (object value in values)
                        {
                            list.Add(value);
                        }

                        IList cloneList = new ArrayList(list);

                        if (mList != null)
                        {
                            mList.MuteNotify = stackMute;
                        }

                        om.SetOriginalPropertyValue(obj, propertyMap.Name, cloneList);
                        om.SetNullValueStatus(obj, propertyMap.Name, false);
                    }
                    else
                    {
                        object value = clone.PropertyValues[propertyMap.Name];
                        om.SetPropertyValue(obj, propertyMap.Name, value);
                        om.SetOriginalPropertyValue(obj, propertyMap.Name, value);
                        om.SetNullValueStatus(obj, propertyMap.Name, (bool)clone.NullValueStatuses[propertyMap.Name]);
                    }
                }
                else
                {
                    IClassMap refClassMap = propertyMap.MustGetReferencedClassMap();
                    if (refClassMap.IsReadOnly)
                    {
                        if (propertyMap.IsCollection)
                        {
                            IList values = (IList)clone.PropertyValues[propertyMap.Name];
                            IList list   = (IList)om.GetPropertyValue(obj, propertyMap.Name);

                            bool stackMute           = false;
                            IInterceptableList mList = list as IInterceptableList;
                            if (mList != null)
                            {
                                stackMute        = mList.MuteNotify;
                                mList.MuteNotify = true;
                            }
                            list.Clear();

                            foreach (SerializedReference refId in values)
                            {
                                object value = null;
                                if (refId != null)
                                {
                                    refClassMap = dm.MustGetClassMap(refId.Type);
                                    Type refType = am.GetTypeFromClassMap(refClassMap);
                                    value = this.Context.GetObjectById(refId.Identity, refType, true);
                                    list.Add(value);
                                }
                            }

                            IList cloneList = new ArrayList(list);

                            if (mList != null)
                            {
                                mList.MuteNotify = stackMute;
                            }

                            om.SetOriginalPropertyValue(obj, propertyMap.Name, cloneList);
                            om.SetNullValueStatus(obj, propertyMap.Name, false);
                        }
                        else
                        {
                            object value = null;
                            SerializedReference refId = (SerializedReference)clone.PropertyValues[propertyMap.Name];
                            if (refId != null)
                            {
                                refClassMap = dm.MustGetClassMap(refId.Type);
                                Type refType = am.GetTypeFromClassMap(refClassMap);
                                value = this.Context.GetObjectById(refId.Identity, refType, true);
                            }
                            om.SetPropertyValue(obj, propertyMap.Name, value);
                            om.SetOriginalPropertyValue(obj, propertyMap.Name, value);
                            om.SetNullValueStatus(obj, propertyMap.Name, (bool)clone.NullValueStatuses[propertyMap.Name]);
                        }
                    }
                }
            }
        }