/// <summary> /// If <see cref="IsReadOnly"/> is true then throw <see cref="FactFactoryException"/>. /// </summary> /// <exception cref="FactFactoryException">If <see cref="IsReadOnly"/> is true.</exception> protected virtual void CheckReadOnly() { if (IsReadOnly) { throw CommonHelper.CreateException(ErrorCode.InvalidOperation, $"Fact container is read-only."); } }
/// <inheritdoc/> /// <exception cref="FactFactoryException">Did not find fact type <typeparamref name="TFact"/>.</exception> /// <returns></returns> public virtual TFact GetFact <TFact>() where TFact : IFact { if (TryGetFact <TFact>(out var fact)) { return(fact); } throw CommonHelper.CreateException(ErrorCode.InvalidData, $"Not found type fact with type {GetFactType<TFact>().FactName}."); }
private void InnerAdd <TFact>(TFact fact, IEqualityComparer <IFact> comparer) where TFact : IFact { IFactType factType = fact.GetFactType(); if (ContainerList.Contains(fact, comparer)) { throw CommonHelper.CreateException(ErrorCode.InvalidData, $"The fact container already contains '{factType.FactName}' fact."); } ContainerList.Add(fact); }
/// <inheritdoc/> public TWantAction CreateWantAction <TWantAction>(Func <IEnumerable <IFact>, ValueTask> wantAction, List <IFactType> factTypes, FactWorkOption option) where TWantAction : IWantAction { var result = new WantAction(wantAction, factTypes, option); if (result is TWantAction converted) { return(converted); } throw CommonHelper.CreateException( ErrorCode.InvalidData, $"The result of the ISingleEntityOperations.CreateWantAction cannot be converted to the type {typeof(TWantAction).Name}."); }
/// <inheritdoc/> public virtual TFactResult CreateRuntimeConditionFact <TFactResult>() where TFactResult : IRuntimeConditionFact { var type = typeof(TFact); var resultType = typeof(TFactResult); if (!resultType.IsAssignableFrom(type)) { throw CommonHelper.CreateException(ErrorCode.InvalidFactType, $"{type.FullName} does not implement {resultType.FullName} type."); } else if (type.GetConstructor(Type.EmptyTypes) == null) { throw CommonHelper.CreateException(ErrorCode.InvalidFactType, $"{type.FullName} doesn't have a default constructor."); } return((TFactResult)Activator.CreateInstance(type, false)); }
/// <summary> /// Error creating version incompatibility. /// </summary> /// <param name="versionedFact"></param> /// <returns></returns> protected virtual FactFactoryException CreateIncompatibilityVersionException(IVersionFact versionedFact) { return(CommonHelper.CreateException(ErrorCode.InvalidFactType, $"Unable to compare versions {GetFactType().FactName} and {versionedFact.GetFactType().FactName}.")); }