Exemplo n.º 1
0
        /// <summary>
        /// Checking the equality of facts.
        /// </summary>
        /// <typeparam name="TWantAction"></typeparam>
        /// <typeparam name="TFactContainer"></typeparam>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public virtual bool EqualsFacts <TWantAction, TFactContainer>(IFact first, IFact second, IWantActionContext <TWantAction, TFactContainer> context)
            where TWantAction : IWantAction
            where TFactContainer : IFactContainer
        {
            if (first == null && second == null)
            {
                return(true);
            }
            if (!FactEqualityComparer.EqualsFacts(first, second, cache: context.Cache, includeFactParams: false))
            {
                return(false);
            }

            IReadOnlyCollection <IFactParameter> firstParameters  = first.GetParameters();
            IReadOnlyCollection <IFactParameter> secondParameters = second.GetParameters();

            if (firstParameters.IsNullOrEmpty() && secondParameters.IsNullOrEmpty())
            {
                return(true);
            }
            if (firstParameters.IsNullOrEmpty() || secondParameters.IsNullOrEmpty())
            {
                return(false);
            }
            if (firstParameters.Count != secondParameters.Count)
            {
                return(false);
            }

            foreach (IFactParameter xParameter in firstParameters)
            {
                bool found = false;

                foreach (IFactParameter yParameter in secondParameters)
                {
                    if (EqualsFactParameters(xParameter, yParameter, context))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    return(false);
                }
            }

            return(true);
        }