Пример #1
0
        private static IIbanNetOptionsBuilder UseValidationMethod(this IIbanNetOptionsBuilder builder, ValidationMethod validationMethod)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.Configure(options => options.Method = validationMethod));
        }
Пример #2
0
        /// <summary>
        /// Registers a handler to configure the options when the builder executes.
        /// </summary>
        /// <param name="builder">The builder instance.</param>
        /// <param name="configure">The handler that is called when configuring the options.</param>
        public static IIbanNetOptionsBuilder Configure(this IIbanNetOptionsBuilder builder, Action <IbanValidatorOptions> configure)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configure is null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            return(builder.Configure((_, options) => configure(options)));
        }
Пример #3
0
        /// <summary>
        /// Registers a custom validation rule that is executed after built-in validation has passed.
        /// </summary>
        /// <param name="builder">The builder instance.</param>
        /// <param name="implementationType">The type of the validation rule.</param>
        /// <returns>The <see cref="IIbanNetOptionsBuilder" /> so that additional calls can be chained.</returns>
        public static IIbanNetOptionsBuilder WithRule(this IIbanNetOptionsBuilder builder, Type implementationType)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (implementationType is null)
            {
                throw new ArgumentNullException(nameof(implementationType));
            }

            return(builder.Configure(
                       (adapter, options) => options.Rules.Add((IIbanValidationRule)adapter.GetRequiredService(implementationType))
                       ));
        }
Пример #4
0
        /// <summary>
        /// Registers a handler to configure the options when the builder executes.
        /// </summary>
        /// <param name="builder">The builder instance.</param>
        /// <param name="configure">The handler that is called when configuring the options.</param>
        /// <returns>The <see cref="IIbanNetOptionsBuilder" /> so that additional calls can be chained.</returns>
        public static IIbanNetOptionsBuilder Configure(this IIbanNetOptionsBuilder builder, Action <IComponentContext, IbanValidatorOptions> configure)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configure is null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            return(builder.Configure(
                       (adapter, options) => configure(adapter.GetRequiredService <IComponentContext>(), options)
                       ));
        }
Пример #5
0
        /// <summary>
        /// Registers a custom validation rule that is executed after built-in validation has passed.
        /// </summary>
        /// <typeparam name="T">The type of the validation rule.</typeparam>
        /// <param name="builder">The builder instance.</param>
        /// <param name="implementationFactory">The factory returning a new instance of the rule.</param>
        /// <returns>The <see cref="IIbanNetOptionsBuilder" /> so that additional calls can be chained.</returns>
        public static IIbanNetOptionsBuilder WithRule <T>(this IIbanNetOptionsBuilder builder, Func <T> implementationFactory)
            where T : class, IIbanValidationRule
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (implementationFactory is null)
            {
                throw new ArgumentNullException(nameof(implementationFactory));
            }

            return(builder.Configure(
                       options => options.Rules.Add(implementationFactory())
                       ));
        }