< Summary

Information
Class: Allyaria.Theming.StyleTypes.StyleOverflowWrap
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StyleOverflowWrap.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 93
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/StyleOverflowWrap.cs

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>overflow-wrap</c> value within the Allyaria theming system. Provides a strongly typed wrapper fo
 5/// controlling word-breaking behavior within elements when text exceeds its container.
 6/// </summary>
 7public sealed record StyleOverflowWrap : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleOverflowWrap" /> record using the specified <see cref="Kind" /
 11    /// value.
 12    /// </summary>
 13    /// <param name="kind">The overflow-wrap behavior to represent.</param>
 14    public StyleOverflowWrap(Kind kind)
 2415        : base(value: kind.GetDescription()) { }
 16
 17    /// <summary>Defines the supported CSS <c>overflow-wrap</c> property values.</summary>
 18    public enum Kind
 19    {
 20        /// <summary>
 21        /// Allows words to be broken at arbitrary points if necessary to prevent overflow. This mode provides maximum f
 22        /// to avoid overflow.
 23        /// </summary>
 24        [Description(description: "anywhere")]
 25        Anywhere,
 26
 27        /// <summary>
 28        /// Breaks words only if necessary to prevent overflow, similar to <c>normal</c>, but allows breaking within wor
 29        /// they would otherwise overflow.
 30        /// </summary>
 31        [Description(description: "break-word")]
 32        BreakWord,
 33
 34        /// <summary>
 35        /// Uses default line-breaking rules; words will only wrap at allowed break points (such as spaces or hyphens).
 36        /// </summary>
 37        [Description(description: "normal")]
 38        Normal
 39    }
 40
 41    /// <summary>
 42    /// Parses a string representation of a CSS <c>overflow-wrap</c> value into a <see cref="StyleOverflowWrap" /> insta
 43    /// </summary>
 44    /// <param name="value">The string representation of the overflow-wrap value.</param>
 45    /// <returns>A new <see cref="StyleOverflowWrap" /> instance representing the parsed value.</returns>
 46    /// <exception cref="AryArgumentException">
 47    /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />.
 48    /// </exception>
 49    public static StyleOverflowWrap Parse(string? value)
 1050        => value.TryParseEnum<Kind>(result: out var kind)
 1051            ? new StyleOverflowWrap(kind: kind)
 1052            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 53
 54    /// <summary>Attempts to parse a string into a <see cref="StyleOverflowWrap" /> instance.</summary>
 55    /// <param name="value">The string representation of the overflow-wrap value to parse.</param>
 56    /// <param name="result">
 57    /// When this method returns, contains the parsed <see cref="StyleOverflowWrap" /> instance or <see langword="null" 
 58    /// parsing failed.
 59    /// </param>
 60    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 61    public static bool TryParse(string? value, out StyleOverflowWrap? result)
 62    {
 63        try
 64        {
 365            result = Parse(value: value);
 66
 167            return true;
 68        }
 269        catch
 70        {
 271            result = null;
 72
 273            return false;
 74        }
 375    }
 76
 77    /// <summary>Implicitly converts a string into a <see cref="StyleOverflowWrap" /> instance.</summary>
 78    /// <param name="value">The string representation of the overflow-wrap value.</param>
 79    /// <returns>A <see cref="StyleOverflowWrap" /> instance representing the provided value.</returns>
 80    /// <exception cref="AryArgumentException">
 81    /// Thrown when the provided string cannot be parsed into a valid
 82    /// <see cref="Kind" />.
 83    /// </exception>
 284    public static implicit operator StyleOverflowWrap(string? value) => Parse(value: value);
 85
 86    /// <summary>Implicitly converts a <see cref="StyleOverflowWrap" /> instance to its string representation.</summary>
 87    /// <param name="value">The <see cref="StyleOverflowWrap" /> instance to convert.</param>
 88    /// <returns>
 89    /// The underlying CSS <c>overflow-wrap</c> string value, or an empty string if <paramref name="value" /> is
 90    /// <see langword="null" />.
 91    /// </returns>
 292    public static implicit operator string(StyleOverflowWrap? value) => (value?.Value).OrDefaultIfEmpty();
 93}