< Summary

Information
Class: MyNet.Observable.AbstractValidatorLocalizedExtensions
Assembly: MyNet.Observable
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Validation/Extensions/AbstractValidatorLocalizedExtensions.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 40
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
RuleForLocalized(...)50%22100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Validation/Extensions/AbstractValidatorLocalizedExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="AbstractValidatorLocalizedExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Linq.Expressions;
 9using FluentValidation;
 10using MyNet.Observable.Validation;
 11using MyNet.Primitives;
 12
 13#pragma warning disable IDE0130 // Namespace does not match folder structure
 14namespace MyNet.Observable;
 15#pragma warning restore IDE0130 // Namespace does not match folder structure
 16
 17/// <summary>
 18/// Starts a localized validation rule from a property expression.
 19/// </summary>
 20public static class AbstractValidatorLocalizedExtensions
 21{
 22    /// <summary>
 23    /// Begins a rule for <paramref name="expression"/> with the property display key inferred from the member name.
 24    /// </summary>
 25    /// <param name="validator">The validator instance.</param>
 26    /// <param name="expression">The property expression (e.g. <c>x => x.Email</c>).</param>
 27    /// <param name="propertyDisplayKey">Optional translation key when it differs from the member name.</param>
 28    public static LocalizedRuleBuilder<T, TProperty> RuleForLocalized<T, TProperty>(
 29        this AbstractValidator<T> validator,
 30        Expression<Func<T, TProperty>> expression,
 31        string? propertyDisplayKey = null)
 32    {
 3033        ArgumentNullException.ThrowIfNull(validator);
 3034        ArgumentNullException.ThrowIfNull(expression);
 35
 3036        var key = propertyDisplayKey ?? expression.PropertyName();
 3037        return new(validator.RuleFor(expression), key);
 38    }
 39}
 40