< Summary

Information
Class: MyNet.Observable.Validation.ValidationMessages
Assembly: MyNet.Observable
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Validation/ValidationMessages.cs
Tag: 323_28699572109
Line coverage
90%
Covered lines: 10
Uncovered lines: 1
Coverable lines: 11
Total lines: 55
Line coverage: 90.9%
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
Format(...)100%11100%
FormatForPropertyKey(...)50%2280%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ValidationMessages.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Globalization;
 9using MyNet.Globalization.Facade;
 10using MyNet.Observable.Localization;
 11using MyNet.Primitives;
 12
 13namespace MyNet.Observable.Validation;
 14
 15/// <summary>
 16/// Formats localized validation messages from <see cref="ValidationResources"/>.
 17/// </summary>
 18public static class ValidationMessages
 19{
 20    /// <summary>
 21    /// Formats a validation template using an already resolved property display name.
 22    /// </summary>
 23    /// <param name="template">The localized message template ({0} = field name).</param>
 24    /// <param name="propertyDisplayName">The resolved display name inserted at {0}.</param>
 25    /// <param name="args">Additional format arguments starting at {1}.</param>
 26    public static string Format(string template, string propertyDisplayName, params object?[] args)
 27    {
 2128        ArgumentException.ThrowIfNullOrEmpty(template);
 2129        ArgumentException.ThrowIfNullOrEmpty(propertyDisplayName);
 30
 2131        var formatArgs = new object?[args.Length + 1];
 2132        formatArgs[0] = propertyDisplayName;
 2133        args.CopyTo(formatArgs, 1);
 34
 2135        return template.FormatWith(CultureInfo.CurrentCulture, formatArgs);
 36    }
 37
 38    /// <summary>
 39    /// Formats a validation template by translating the property key with the current culture.
 40    /// </summary>
 41    /// <param name="template">The localized message template ({0} = field name).</param>
 42    /// <param name="propertyDisplayKey">The translation key for the property display name.</param>
 43    /// <param name="args">Additional format arguments starting at {1}.</param>
 44    public static string FormatForPropertyKey(string template, string propertyDisplayKey, params object?[] args)
 45    {
 1546        ArgumentException.ThrowIfNullOrEmpty(propertyDisplayKey);
 47
 1548        var displayName = propertyDisplayKey.Translate();
 1549        if (string.IsNullOrWhiteSpace(displayName))
 050            displayName = propertyDisplayKey;
 51
 1552        return Format(template, displayName, args);
 53    }
 54}
 55