Ejemplo n.º 1
0
        internal static PropertyInfoList GetPropertyListCache(Type objectType)
        {
            var cache = PropertyInfoCache;

#if NET5_0_OR_GREATER
            var found = cache.TryGetValue(objectType, out var listInfo);

            var list = listInfo?.Item2;

            if (!found)
            {
                lock (cache)
                {
                    found = cache.TryGetValue(objectType, out listInfo);

                    if (!found)
                    {
                        list = new PropertyInfoList();

                        var cacheInstance = AssemblyLoadContextManager.CreateCacheInstance(objectType, list, OnAssemblyLoadContextUnload);

                        cache.Add(objectType, cacheInstance);

                        FieldDataManager.ForceStaticFieldInit(objectType);
                    }
                }
            }
#else
            var found = cache.TryGetValue(objectType, out PropertyInfoList list);

            if (!found)
            {
                lock (cache)
                {
                    found = cache.TryGetValue(objectType, out list);

                    if (!found)
                    {
                        list = new PropertyInfoList();

                        cache.Add(objectType, list);

                        FieldDataManager.ForceStaticFieldInit(objectType);
                    }
                }
            }
#endif

            return(list);
        }
Ejemplo n.º 2
0
        internal static PropertyInfoList GetPropertyListCache(Type objectType)
        {
            var cache = PropertyInfoCache;
            var found = cache.TryGetValue(objectType, out PropertyInfoList list);

            if (!found)
            {
                lock (cache)
                {
                    found = cache.TryGetValue(objectType, out list);
                    if (!found)
                    {
                        list = new PropertyInfoList();
                        cache.Add(objectType, list);
                        FieldDataManager.ForceStaticFieldInit(objectType);
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Merges state from source graph into target graph.
        /// </summary>
        /// <param name="target">Target of merge.</param>
        /// <param name="source">Source for merge.</param>
        public void MergeGraph(IEditableBusinessObject target, IEditableBusinessObject source)
        {
            if (target is IManageProperties imp)
            {
                FieldManager.FieldDataManager targetFieldManager = null;
                if (target is IUseFieldManager iufm)
                {
                    targetFieldManager = iufm.FieldManager;
                }
                FieldManager.FieldDataManager sourceFieldManager = null;
                if (source is IUseFieldManager iufms)
                {
                    sourceFieldManager = iufms.FieldManager;
                }

                var targetProperties = imp.GetManagedProperties();
                foreach (var item in targetProperties)
                {
                    var sourceFieldExists = true;
                    if (sourceFieldManager != null && (item.RelationshipType & RelationshipTypes.LazyLoad) == RelationshipTypes.LazyLoad)
                    {
                        sourceFieldExists = sourceFieldManager.FieldExists(item);
                    }
                    object sourceValue = null;
                    if (sourceFieldExists)
                    {
                        sourceValue = ReadProperty(source, item);
                    }
                    if (sourceValue is IEditableBusinessObject sourceChild)
                    {
                        var targetFieldExists = true;
                        if (targetFieldManager != null && (item.RelationshipType & RelationshipTypes.LazyLoad) == RelationshipTypes.LazyLoad)
                        {
                            targetFieldExists = targetFieldManager.FieldExists(item);
                        }
                        if (targetFieldExists && ReadProperty(target, item) is IEditableBusinessObject targetChild)
                        {
                            MergeGraph(targetChild, sourceChild);
                        }
                        else
                        {
                            if ((item.RelationshipType & RelationshipTypes.PrivateField) == RelationshipTypes.PrivateField)
                            {
                                Csla.Reflection.MethodCaller.CallPropertySetter(target, item.Name, sourceChild);
                            }
                            else
                            {
                                LoadProperty(target, item, sourceChild);
                            }
                        }
                    }
                    else
                    {
                        if (sourceValue is IEditableCollection sourceList)
                        {
                            var targetFieldExists = true;
                            if (targetFieldManager != null && (item.RelationshipType & RelationshipTypes.LazyLoad) == RelationshipTypes.LazyLoad)
                            {
                                targetFieldExists = targetFieldManager.FieldExists(item);
                            }
                            if (targetFieldExists && ReadProperty(target, item) is IEditableCollection targetList)
                            {
                                MergeGraph(targetList, sourceList);
                            }
                            else
                            {
                                if ((item.RelationshipType & RelationshipTypes.PrivateField) == RelationshipTypes.PrivateField)
                                {
                                    Csla.Reflection.MethodCaller.CallPropertySetter(target, item.Name, sourceList);
                                }
                                else
                                {
                                    LoadProperty(target, item, sourceList);
                                }
                            }
                        }
                        else
                        {
                            if ((item.RelationshipType & RelationshipTypes.PrivateField) == RelationshipTypes.PrivateField)
                            {
                                Csla.Reflection.MethodCaller.CallPropertySetter(target, item.Name, sourceValue);
                            }
                            else
                            {
                                LoadProperty(target, item, sourceValue);
                            }
                        }
                    }
                }
                if (source.IsNew)
                {
                    MarkNew(target);
                }
                else if (!source.IsDirty)
                {
                    MarkOld(target);
                }
                else
                {
                    CopyField(source, target, "_isDirty");
                    CopyField(source, target, "_isNew");
                    CopyField(source, target, "_isDeleted");
                }
                CheckRules(target);
            }
        }