コード例 #1
0
        /// <inheritdoc/>
        protected override bool IsValid(PropertyValidatorContext context)
        {
            WorkflowDefinition workflow = (WorkflowDefinition)context.InstanceToValidate;
            IEnumerable <FunctionDefinition> functions = (IEnumerable <FunctionDefinition>)context.PropertyValue;
            int index = 0;
            IValidator <FunctionDefinition> validator = new FunctionDefinitionValidator(workflow);

            foreach (FunctionDefinition function in functions)
            {
                ValidationResult validationResult = validator.Validate(function);
                if (validationResult.IsValid)
                {
                    index++;
                    continue;
                }
                this.ErrorCode = $"{context.PropertyName}[{index}]";
                this.SetErrorMessage(string.Join(Environment.NewLine, validationResult.Errors.Select(e => $"{e.ErrorCode}: {e.ErrorMessage}")));
                return(false);
            }
            return(true);
        }
        /// <inheritdoc/>
        public override bool IsValid(ValidationContext <WorkflowDefinition> context, IEnumerable <FunctionDefinition> value)
        {
            WorkflowDefinition workflow = context.InstanceToValidate;
            int index = 0;
            IValidator <FunctionDefinition> validator = new FunctionDefinitionValidator(workflow);

            foreach (FunctionDefinition function in value)
            {
                ValidationResult validationResult = validator.Validate(function);
                if (validationResult.IsValid)
                {
                    index++;
                    continue;
                }
                foreach (var failure in validationResult.Errors)
                {
                    context.AddFailure(failure);
                }
                return(false);
            }
            return(true);
        }