< Summary

Information
Class: Allyaria.Theming.Values.AllyariaStringValue
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Values/AllyariaStringValue.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 62
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Normalize(...)100%11100%
Parse(...)100%11100%
TryParse(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Values/AllyariaStringValue.cs

#LineLine coverage
 1using Allyaria.Theming.Contracts;
 2
 3namespace Allyaria.Theming.Values;
 4
 5/// <summary>Represents a theming string value with enforced normalization (trimmed, non-null, non-whitespace).</summary
 6public sealed class AllyariaStringValue : ValueBase
 7{
 8    /// <summary>Initializes a new instance of the <see cref="AllyariaStringValue" /> class.</summary>
 9    /// <param name="value">The string value to normalize and store.</param>
 10    /// <exception cref="ArgumentException">Thrown when <paramref name="value" /> is <c>null</c>, empty, or whitespace.<
 11    public AllyariaStringValue(string value)
 61412        : base(Normalize(value)) { }
 13
 14    /// <summary>Normalizes the input string by trimming and validating it.</summary>
 15    /// <param name="value">The string value to normalize.</param>
 16    /// <returns>The normalized (trimmed) string.</returns>
 17    /// <exception cref="ArgumentException">
 18    /// Thrown when <paramref name="value" /> is <c>null</c>, empty, whitespace, or contains control characters.
 19    /// </exception>
 32020    private static string Normalize(string value) => ValidateInput(value);
 21
 22    /// <summary>Parses the specified string into an <see cref="AllyariaStringValue" />.</summary>
 23    /// <param name="value">The input string to parse.</param>
 24    /// <returns>A new <see cref="AllyariaStringValue" /> containing the normalized <paramref name="value" />.</returns>
 25    /// <exception cref="ArgumentException">Thrown when <paramref name="value" /> is <c>null</c>, empty, or whitespace.<
 1026    public static AllyariaStringValue Parse(string value) => new(value);
 27
 28    /// <summary>Attempts to parse the specified string into an <see cref="AllyariaStringValue" />.</summary>
 29    /// <param name="value">The input string to parse.</param>
 30    /// <param name="result">
 31    /// When this method returns, contains the parsed <see cref="AllyariaStringValue" /> if parsing succeeded, or <c>nul
 32    /// if it failed.
 33    /// </param>
 34    /// <returns><c>true</c> if parsing succeeded; otherwise, <c>false</c>.</returns>
 35    public static bool TryParse(string value, out AllyariaStringValue? result)
 36    {
 37        try
 38        {
 839            result = new AllyariaStringValue(value);
 40
 241            return true;
 42        }
 643        catch
 44        {
 645            result = null;
 46
 647            return false;
 48        }
 849    }
 50
 51    /// <summary>Defines an implicit conversion from <see cref="string" /> to <see cref="AllyariaStringValue" />.</summa
 52    /// <param name="value">The string value to convert.</param>
 53    /// <returns>A new <see cref="AllyariaStringValue" /> containing the normalized <paramref name="value" />.</returns>
 54    /// <exception cref="ArgumentException">Thrown when <paramref name="value" /> is <c>null</c>, empty, or whitespace.<
 855    public static implicit operator AllyariaStringValue(string value) => new(value);
 56
 57    /// <summary>Defines an implicit conversion from <see cref="AllyariaStringValue" /> to <see cref="string" />.</summa
 58    /// <param name="value">The <see cref="AllyariaStringValue" /> instance.</param>
 59    /// <returns>The underlying normalized string value.</returns>
 60    /// <exception cref="ArgumentNullException">Thrown when <paramref name="value" /> is <c>null</c>.</exception>
 261    public static implicit operator string(AllyariaStringValue value) => value.Value;
 62}