< Summary

Information
Class: Allyaria.Theming.StyleTypes.StyleHyphens
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StyleHyphens.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 91
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StyleHyphens.cs

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>hyphens</c> value within the Allyaria theming system. Provides a strongly typed wrapper for
 5/// defining how words may be hyphenated when text wraps.
 6/// </summary>
 7public sealed record StyleHyphens : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleHyphens" /> record using the specified <see cref="Kind" /> val
 11    /// </summary>
 12    /// <param name="kind">The hyphenation behavior kind to represent.</param>
 13    public StyleHyphens(Kind kind)
 2414        : base(value: kind.GetDescription()) { }
 15
 16    /// <summary>Defines the supported CSS <c>hyphens</c> property values.</summary>
 17    public enum Kind
 18    {
 19        /// <summary>
 20        /// The browser automatically inserts hyphens where appropriate according to the language rules and available hy
 21        /// dictionary.
 22        /// </summary>
 23        [Description(description: "auto")]
 24        Auto,
 25
 26        /// <summary>
 27        /// Hyphens are inserted only where the author has explicitly specified soft hyphens (<c>&amp;shy;</c>) in the t
 28        /// </summary>
 29        [Description(description: "manual")]
 30        Manual,
 31
 32        /// <summary>
 33        /// Hyphenation is disabled entirely; words will not be broken and will overflow or wrap at spaces only.
 34        /// </summary>
 35        [Description(description: "none")]
 36        None
 37    }
 38
 39    /// <summary>
 40    /// Parses a string representation of a CSS <c>hyphens</c> value into a <see cref="StyleHyphens" /> instance.
 41    /// </summary>
 42    /// <param name="value">The string representation of the hyphens value.</param>
 43    /// <returns>A new <see cref="StyleHyphens" /> instance representing the parsed value.</returns>
 44    /// <exception cref="AryArgumentException">
 45    /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />.
 46    /// </exception>
 47    public static StyleHyphens Parse(string? value)
 1048        => value.TryParseEnum<Kind>(result: out var kind)
 1049            ? new StyleHyphens(kind: kind)
 1050            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 51
 52    /// <summary>Attempts to parse a string into a <see cref="StyleHyphens" /> instance.</summary>
 53    /// <param name="value">The string representation of the hyphens value to parse.</param>
 54    /// <param name="result">
 55    /// When this method returns, contains the parsed <see cref="StyleHyphens" /> instance or <see langword="null" /> if
 56    /// parsing failed.
 57    /// </param>
 58    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 59    public static bool TryParse(string? value, out StyleHyphens? result)
 60    {
 61        try
 62        {
 363            result = Parse(value: value);
 64
 165            return true;
 66        }
 267        catch
 68        {
 269            result = null;
 70
 271            return false;
 72        }
 373    }
 74
 75    /// <summary>Implicitly converts a string into a <see cref="StyleHyphens" /> instance.</summary>
 76    /// <param name="value">The string representation of the hyphens value.</param>
 77    /// <returns>A <see cref="StyleHyphens" /> instance representing the provided value.</returns>
 78    /// <exception cref="AryArgumentException">
 79    /// Thrown when the provided string cannot be parsed into a valid
 80    /// <see cref="Kind" />.
 81    /// </exception>
 282    public static implicit operator StyleHyphens(string? value) => Parse(value: value);
 83
 84    /// <summary>Implicitly converts a <see cref="StyleHyphens" /> instance to its string representation.</summary>
 85    /// <param name="value">The <see cref="StyleHyphens" /> instance to convert.</param>
 86    /// <returns>
 87    /// The underlying CSS <c>hyphens</c> string value, or an empty string if <paramref name="value" /> is
 88    /// <see langword="null" />.
 89    /// </returns>
 290    public static implicit operator string(StyleHyphens? value) => (value?.Value).OrDefaultIfEmpty();
 91}