Ejemplo n.º 1
0
        /// <summary>
        /// Initialises a new instance of <see cref="RuleContext"/>.
        /// </summary>
        /// <param name="manifestRule">The manifest rule from which this context was created.</param>
        /// <param name="ruleIdentifier">The rule identifier.</param>
        /// <param name="actualValue">The actual validated value.</param>
        /// <param name="ancestorContexts">A collection of ancestor contexts.</param>
        /// <param name="ruleInterface">The rule interface used for this rule execution.</param>
        /// <param name="collectionItemOrder">An optional collection item order.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public RuleContext(ManifestRule manifestRule,
                           RuleIdentifier ruleIdentifier,
                           object actualValue,
                           IEnumerable <ValueContext> ancestorContexts,
                           Type ruleInterface,
                           long?collectionItemOrder = null)
            : base(ruleIdentifier?.ObjectIdentity, actualValue, manifestRule?.ManifestValue, collectionItemOrder)
        {
            if (manifestRule is null)
            {
                throw new ArgumentNullException(nameof(manifestRule));
            }
            if (ancestorContexts is null)
            {
                throw new ArgumentNullException(nameof(ancestorContexts));
            }

            RuleInfo         = new ManifestRuleInfo(manifestRule);
            RuleIdentifier   = ruleIdentifier ?? throw new ArgumentNullException(nameof(ruleIdentifier));
            RuleInterface    = ruleInterface ?? throw new ArgumentNullException(nameof(ruleInterface));
            AncestorContexts = new List <ValueContext>(ancestorContexts);
        }
Ejemplo n.º 2
0
        ValidationRuleResult GetValidationRuleResult(RuleResult result, ManifestRule manifestRule, RuleIdentifier ruleIdentifier, IValidationLogic logic)
        {
            var valueContext = new ValueContext(Guid.NewGuid(), ParentValue, manifestRule.ManifestValue);
            var context      = new RuleContext(manifestRule, ruleIdentifier, ValidatedValue, new [] { valueContext }, RuleInterface);

            return(new ValidationRuleResult(result, context, logic));
        }