All Downloads are FREE. Search and download functionalities are using the official Maven repository.

NetStandard.2.1.Rosetta.Validation.AbstractChoiceRule.cs Maven / Gradle / Ivy

The newest version!
#nullable enable // Allow nullable reference types

namespace Rosetta.Lib.Validation
{
    using System;
    using System.Collections.Generic;

    public abstract class AbstractChoiceRule : IValidator where T : IRosettaModelObject
    {
        protected string Name => GetType().Name;

        protected abstract IEnumerable ChoiceFieldNames { get; }

        protected abstract IChoiceRuleValidationMethod ValidationMethod { get; }

        protected abstract ICollection GetPopulatedFieldNames(T obj);

        public IValidationResult Validate(T obj)
        {
            var validationMethod = ValidationMethod;
            var populatedFieldNames = GetPopulatedFieldNames(obj);

            if (validationMethod.Check(populatedFieldNames.Count))
            {
                return ModelValidationResult.Success(Name, ValidationType.CHOICE_RULE, nameof(T));
            }
            return new ChoiceRuleFailure(Name, nameof(T), ChoiceFieldNames, populatedFieldNames, validationMethod);
        }

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy