internal static CriteriaCollection Clone(CriteriaCollection criteriaCollection)
        {
            var newCriteriaCollection = new CriteriaCollection();

            foreach (var crit in criteriaCollection)
            {
                newCriteriaCollection.Add(Criteria.Clone(crit));
            }

            return(newCriteriaCollection);
        }
        /// <summary>
        /// Filters and merges the unit of work criteria collection.
        /// Collection is filtered according to the type of criteria and type of the Unit of Work Type under processing.
        /// </summary>
        /// <param name="info">The info.</param>
        /// <returns>
        /// A single filtered collection of critera.
        /// </returns>
        public static List <CriteriaCollection> GetAllCriteria(CslaObjectInfo info)
        {
            if (info.IsUpdater)
            {
                return(null);
            }

            var mergeTypes = new List <CriteriaMergeType>();

            if (info.UnitOfWorkType == UnitOfWorkFunction.Creator ||
                info.UnitOfWorkType == UnitOfWorkFunction.CreatorGetter)
            {
                mergeTypes.Add(CriteriaMergeType.Create);
            }

            if (info.UnitOfWorkType == UnitOfWorkFunction.Getter ||
                info.UnitOfWorkType == UnitOfWorkFunction.CreatorGetter)
            {
                mergeTypes.Add(CriteriaMergeType.Get);
            }

            if (info.UnitOfWorkType == UnitOfWorkFunction.Deleter)
            {
                mergeTypes.Add(CriteriaMergeType.Delete);
            }

            var result = new List <CriteriaCollection>();

            foreach (var mergeType in mergeTypes)
            {
                _buffer = new List <CriteriaCollection>();
                foreach (var prop in info.UnitOfWorkProperties)
                {
                    _criteriaCache = new List <Criteria>();
                    var targetInfo = info.Parent.CslaObjects.Find(prop.TypeName);
                    var index      = 0;
                    foreach (var crit in targetInfo.CriteriaObjects)
                    {
                        if (mergeType.HasFlag(CriteriaMergeType.Create) && crit.IsCreator)
                        {
                            var newCriteria = Criteria.Clone(crit);
                            newCriteria.GetOptions.Disable();
                            newCriteria.DeleteOptions.Disable();
                            if (info.UnitOfWorkType == UnitOfWorkFunction.CreatorGetter)
                            {
                                index++;
                                if (newCriteria.Properties.Count == 0)
                                {
                                    newCriteria.Properties.AddRange(GetFakeCreateCriteria(targetInfo, index));
                                }
                            }
                            _criteriaCache.Add(newCriteria);
                        }
                        else if (mergeType.HasFlag(CriteriaMergeType.Create) && crit.IsGetter && !prop.CreatesObject)
                        {
                            _criteriaCache.Add(Criteria.Clone(crit));
                        }
                        else if (mergeType.HasFlag(CriteriaMergeType.Get) && crit.IsGetter)
                        {
                            var newCriteria = Criteria.Clone(crit);
                            newCriteria.CreateOptions.Disable();
                            newCriteria.DeleteOptions.Disable();
                            if (info.UnitOfWorkType == UnitOfWorkFunction.CreatorGetter && prop.CreatesObject)
                            {
                                foreach (var property in newCriteria.Properties)
                                {
                                    property.UnitOfWorkFactoryParameter = "false";
                                }
                            }
                            _criteriaCache.Add(newCriteria);
                        }
                        else if (mergeType.HasFlag(CriteriaMergeType.Delete) && crit.IsDeleter)
                        {
                            var newCriteria = Criteria.Clone(crit);
                            newCriteria.CreateOptions.Disable();
                            newCriteria.GetOptions.Disable();
                            _criteriaCache.Add(newCriteria);
                        }
                    }
                    if (_criteriaCache.Count == 0)
                    {
                        continue;
                    }

                    PrepareCriteriaList();
                    AssignCriteria();
                }
                result.AddRange(_buffer);
            }

            return(result);
        }