/// <inheritdoc/> public virtual void ValidateContainer <TFactContainer>(TFactContainer container) where TFactContainer : IFactContainer { if (container == null) { throw CommonHelper.CreateDeriveException(ErrorCode.InvalidData, "Container cannot be null."); } if (container.Any(fact => fact is IBuildConditionFact)) { throw CommonHelper.CreateDeriveException(ErrorCode.InvalidData, $"Container contains {nameof(IBuildConditionFact)} facts."); } if (container.Any(fact => fact is IRuntimeConditionFact)) { throw CommonHelper.CreateDeriveException(ErrorCode.InvalidData, $"Container contains {nameof(IRuntimeConditionFact)} facts."); } IEqualityComparer <IFact> comparer = container.EqualityComparer ?? FactEqualityComparer.GetDefault(); foreach (var fact in container) { if (container.Count(f => comparer.Equals(f, fact)) != 1) { throw CommonHelper.CreateDeriveException(ErrorCode.InvalidData, $"Using the IEqualityComparer<IFact>, the '{fact.GetFactType().FactName}' fact was not found in the container or was found multiple times."); } } }
/// <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); }
/// <summary> /// Checking the equality of fact parameters. /// </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 EqualsFactParameters <TWantAction, TFactContainer>(IFactParameter first, IFactParameter second, IWantActionContext <TWantAction, TFactContainer> context) where TWantAction : IWantAction where TFactContainer : IFactContainer { return(FactEqualityComparer.EqualsFactParameters(first, second)); }