< Summary

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

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>writing-mode</c> value within the Allyaria theming system. Provides a strongly typed wrapper for
 5/// defining the direction in which text and block content flow.
 6/// </summary>
 7public sealed record StyleWritingMode : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleWritingMode" /> record using the specified <see cref="Kind" />
 11    /// </summary>
 12    /// <param name="kind">The writing mode to represent.</param>
 13    public StyleWritingMode(Kind kind)
 3614        : base(value: kind.GetDescription()) { }
 15
 16    /// <summary>Defines the supported CSS <c>writing-mode</c> property values.</summary>
 17    public enum Kind
 18    {
 19        /// <summary>
 20        /// Text and blocks flow horizontally from left to right, with new lines stacked vertically top to bottom (defau
 21        /// </summary>
 22        [Description(description: "horizontal-tb")]
 23        HorizontalTb,
 24
 25        /// <summary>Text and blocks flow sideways left-to-right, with vertical lines stacked horizontally.</summary>
 26        [Description(description: "sideways-lr")]
 27        SidewaysLr,
 28
 29        /// <summary>Text and blocks flow sideways right-to-left, with vertical lines stacked horizontally.</summary>
 30        [Description(description: "sideways-rl")]
 31        SidewaysRl,
 32
 33        /// <summary>Text and blocks flow vertically from top to bottom, and lines stack from left to right.</summary>
 34        [Description(description: "vertical-lr")]
 35        VerticalLr,
 36
 37        /// <summary>Text and blocks flow vertically from top to bottom, and lines stack from right to left.</summary>
 38        [Description(description: "vertical-rl")]
 39        VerticalRl
 40    }
 41
 42    /// <summary>
 43    /// Parses a string representation of a CSS <c>writing-mode</c> value into a <see cref="StyleWritingMode" /> instanc
 44    /// </summary>
 45    /// <param name="value">The string representation of the writing-mode value.</param>
 46    /// <returns>A new <see cref="StyleWritingMode" /> instance representing the parsed value.</returns>
 47    /// <exception cref="AryArgumentException">
 48    /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />.
 49    /// </exception>
 50    public static StyleWritingMode Parse(string? value)
 1251        => value.TryParseEnum<Kind>(result: out var kind)
 1252            ? new StyleWritingMode(kind: kind)
 1253            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 54
 55    /// <summary>Attempts to parse a string into a <see cref="StyleWritingMode" /> instance.</summary>
 56    /// <param name="value">The string representation of the writing-mode value to parse.</param>
 57    /// <param name="result">
 58    /// When this method returns, contains the parsed <see cref="StyleWritingMode" /> instance or <see langword="null" /
 59    /// parsing failed.
 60    /// </param>
 61    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 62    public static bool TryParse(string? value, out StyleWritingMode? result)
 63    {
 64        try
 65        {
 366            result = Parse(value: value);
 67
 168            return true;
 69        }
 270        catch
 71        {
 272            result = null;
 73
 274            return false;
 75        }
 376    }
 77
 78    /// <summary>Implicitly converts a string into a <see cref="StyleWritingMode" /> instance.</summary>
 79    /// <param name="value">The string representation of the writing-mode value.</param>
 80    /// <returns>A <see cref="StyleWritingMode" /> instance representing the provided value.</returns>
 81    /// <exception cref="AryArgumentException">
 82    /// Thrown when the provided string cannot be parsed into a valid
 83    /// <see cref="Kind" />.
 84    /// </exception>
 285    public static implicit operator StyleWritingMode(string? value) => Parse(value: value);
 86
 87    /// <summary>Implicitly converts a <see cref="StyleWritingMode" /> instance to its string representation.</summary>
 88    /// <param name="value">The <see cref="StyleWritingMode" /> instance to convert.</param>
 89    /// <returns>
 90    /// The underlying CSS <c>writing-mode</c> string value, or an empty string if <paramref name="value" /> is
 91    /// <see langword="null" />.
 92    /// </returns>
 293    public static implicit operator string(StyleWritingMode? value) => (value?.Value).OrDefaultIfEmpty();
 94}