< Summary

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

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>display</c> value within the Allyaria theming system. Provides a strongly typed wrapper for comm
 5/// CSS display keywords controlling element layout behavior.
 6/// </summary>
 7public sealed record StyleDisplay : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleDisplay" /> record using the specified display <see cref="Kind
 11    /// </summary>
 12    /// <param name="kind">The display kind that determines how the element is rendered in the layout.</param>
 13    public StyleDisplay(Kind kind)
 12614        : base(value: kind.GetDescription()) { }
 15
 16    /// <summary>Defines the supported CSS <c>display</c> property values.</summary>
 17    public enum Kind
 18    {
 19        /// <summary>The element generates a block-level box (starts on a new line, full width by default).</summary>
 20        [Description(description: "block")]
 21        Block,
 22
 23        /// <summary>The element behaves as a flexible container using the Flexbox layout model.</summary>
 24        [Description(description: "flex")]
 25        Flex,
 26
 27        /// <summary>Creates a block-level box that establishes a new block formatting context.</summary>
 28        [Description(description: "flow-root")]
 29        FlowRoot,
 30
 31        /// <summary>The element behaves as a grid container using the CSS Grid layout model.</summary>
 32        [Description(description: "grid")]
 33        Grid,
 34
 35        /// <summary>The element generates one or more inline-level boxes that do not start on a new line.</summary>
 36        [Description(description: "inline")]
 37        Inline,
 38
 39        /// <summary>
 40        /// The element behaves as an inline-level block container (flows inline but accepts block properties).
 41        /// </summary>
 42        [Description(description: "inline-block")]
 43        InlineBlock,
 44
 45        /// <summary>The element behaves as an inline-level flex container.</summary>
 46        [Description(description: "inline-flex")]
 47        InlineFlex,
 48
 49        /// <summary>The element behaves as an inline-level grid container.</summary>
 50        [Description(description: "inline-grid")]
 51        InlineGrid,
 52
 53        /// <summary>The element behaves as an inline-level table container.</summary>
 54        [Description(description: "inline-table")]
 55        InlineTable,
 56
 57        /// <summary>The element behaves as a list item with a marker box (e.g., a bullet).</summary>
 58        [Description(description: "list-item")]
 59        ListItem,
 60
 61        /// <summary>The element is not displayed and takes up no layout space.</summary>
 62        [Description(description: "none")]
 63        None,
 64
 65        /// <summary>The element behaves as a block-level table.</summary>
 66        [Description(description: "table")]
 67        Table,
 68
 69        /// <summary>The element behaves as a table caption.</summary>
 70        [Description(description: "table-caption")]
 71        TableCaption,
 72
 73        /// <summary>The element behaves as a table cell.</summary>
 74        [Description(description: "table-cell")]
 75        TableCell,
 76
 77        /// <summary>The element behaves as a table column.</summary>
 78        [Description(description: "table-column")]
 79        TableColumn,
 80
 81        /// <summary>The element behaves as a group of table columns.</summary>
 82        [Description(description: "table-column-group")]
 83        TableColumnGroup,
 84
 85        /// <summary>The element behaves as a group of table footer rows.</summary>
 86        [Description(description: "table-footer-group")]
 87        TableFooterGroup,
 88
 89        /// <summary>The element behaves as a group of table header rows.</summary>
 90        [Description(description: "table-header-group")]
 91        TableHeaderGroup,
 92
 93        /// <summary>The element behaves as a single table row.</summary>
 94        [Description(description: "table-row")]
 95        TableRow,
 96
 97        /// <summary>The element behaves as a group of table rows.</summary>
 98        [Description(description: "table-row-group")]
 99        TableRowGroup
 100    }
 101
 102    /// <summary>
 103    /// Parses a string representation of a CSS <c>display</c> value into a <see cref="StyleDisplay" /> instance.
 104    /// </summary>
 105    /// <param name="value">The string representation of the display value.</param>
 106    /// <returns>A new <see cref="StyleDisplay" /> instance representing the parsed value.</returns>
 107    /// <exception cref="AryArgumentException">
 108    /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />.
 109    /// </exception>
 110    public static StyleDisplay Parse(string? value)
 27111        => value.TryParseEnum<Kind>(result: out var kind)
 27112            ? new StyleDisplay(kind: kind)
 27113            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 114
 115    /// <summary>Attempts to parse a string into a <see cref="StyleDisplay" /> instance.</summary>
 116    /// <param name="value">The string value to parse.</param>
 117    /// <param name="result">
 118    /// When this method returns, contains the parsed <see cref="StyleDisplay" /> instance or <see langword="null" /> if
 119    /// parsing failed.
 120    /// </param>
 121    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 122    public static bool TryParse(string? value, out StyleDisplay? result)
 123    {
 124        try
 125        {
 3126            result = Parse(value: value);
 127
 1128            return true;
 129        }
 2130        catch
 131        {
 2132            result = null;
 133
 2134            return false;
 135        }
 3136    }
 137
 138    /// <summary>Implicitly converts a string into a <see cref="StyleDisplay" /> instance.</summary>
 139    /// <param name="value">The string representation of the display value.</param>
 140    /// <returns>A <see cref="StyleDisplay" /> instance representing the provided value.</returns>
 141    /// <exception cref="AryArgumentException">
 142    /// Thrown when the provided string cannot be parsed into a valid
 143    /// <see cref="Kind" />.
 144    /// </exception>
 2145    public static implicit operator StyleDisplay(string? value) => Parse(value: value);
 146
 147    /// <summary>Implicitly converts a <see cref="StyleDisplay" /> instance to its string representation.</summary>
 148    /// <param name="value">The <see cref="StyleDisplay" /> instance to convert.</param>
 149    /// <returns>
 150    /// The underlying CSS <c>display</c> string value, or an empty string if <paramref name="value" /> is
 151    /// <see langword="null" />.
 152    /// </returns>
 2153    public static implicit operator string(StyleDisplay? value) => (value?.Value).OrDefaultIfEmpty();
 154}