< Summary

Information
Class: Allyaria.Theming.StyleTypes.StyleFontWeight
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StyleFontWeight.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 130
Line coverage: 100%
Branch coverage
100%
Covered branches: 40
Total branches: 40
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%3838100%
TryParse(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%22100%

File(s)

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

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>font-weight</c> value within the Allyaria theming system. Provides a strongly typed wrapper for
 5/// defining typographic weight (thickness or boldness) of text.
 6/// </summary>
 7public sealed record StyleFontWeight : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleFontWeight" /> record using the specified <see cref="Kind" /> 
 11    /// </summary>
 12    /// <param name="kind">The font weight kind that determines how bold or light the text is rendered.</param>
 13    public StyleFontWeight(Kind kind)
 27814        : base(value: kind.GetDescription()) { }
 15
 16    /// <summary>Defines the supported CSS <c>font-weight</c> property values.</summary>
 17    public enum Kind
 18    {
 19        /// <summary>Specifies bold text, typically equivalent to a numeric weight of 700.</summary>
 20        [Description(description: "bold")]
 21        Bold,
 22
 23        /// <summary>Specifies a font weight bolder than the parent element’s weight.</summary>
 24        [Description(description: "bolder")]
 25        Bolder,
 26
 27        /// <summary>Specifies a font weight lighter than the parent element’s weight.</summary>
 28        [Description(description: "lighter")]
 29        Lighter,
 30
 31        /// <summary>Specifies a normal font weight, typically equivalent to a numeric weight of 400.</summary>
 32        [Description(description: "normal")]
 33        Normal,
 34
 35        /// <summary>Specifies a thin font weight (100).</summary>
 36        [Description(description: "100")]
 37        Weight100,
 38
 39        /// <summary>Specifies an extra-light font weight (200).</summary>
 40        [Description(description: "200")]
 41        Weight200,
 42
 43        /// <summary>Specifies a light font weight (300).</summary>
 44        [Description(description: "300")]
 45        Weight300,
 46
 47        /// <summary>Specifies a normal font weight (400).</summary>
 48        [Description(description: "400")]
 49        Weight400,
 50
 51        /// <summary>Specifies a medium font weight (500).</summary>
 52        [Description(description: "500")]
 53        Weight500,
 54
 55        /// <summary>Specifies a semi-bold font weight (600).</summary>
 56        [Description(description: "600")]
 57        Weight600,
 58
 59        /// <summary>Specifies a bold font weight (700).</summary>
 60        [Description(description: "700")]
 61        Weight700,
 62
 63        /// <summary>Specifies an extra-bold font weight (800).</summary>
 64        [Description(description: "800")]
 65        Weight800,
 66
 67        /// <summary>Specifies a black (heaviest) font weight (900).</summary>
 68        [Description(description: "900")]
 69        Weight900
 70    }
 71
 72    /// <summary>
 73    /// Parses a string representation of a CSS <c>font-weight</c> value into a <see cref="StyleFontWeight" /> instance.
 74    /// </summary>
 75    /// <param name="value">The string representation of the font-weight value.</param>
 76    /// <returns>A new <see cref="StyleFontWeight" /> instance representing the parsed value.</returns>
 77    /// <exception cref="AryArgumentException">
 78    /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />.
 79    /// </exception>
 80    public static StyleFontWeight Parse(string? value)
 81    {
 2082        var valueString = value is "100" or "200" or "300" or "400" or "500" or "600" or "700" or "800" or "900"
 2083            ? $"Weight{value}"
 2084            : value?.Trim();
 85
 2086        return valueString.TryParseEnum<Kind>(result: out var kind)
 2087            ? new StyleFontWeight(kind: kind)
 2088            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 89    }
 90
 91    /// <summary>Attempts to parse a string into a <see cref="StyleFontWeight" /> instance.</summary>
 92    /// <param name="value">The string representation of the font-weight value to parse.</param>
 93    /// <param name="result">
 94    /// When this method returns, contains the parsed <see cref="StyleFontWeight" /> instance or <see langword="null" />
 95    /// parsing failed.
 96    /// </param>
 97    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 98    public static bool TryParse(string? value, out StyleFontWeight? result)
 99    {
 100        try
 101        {
 3102            result = Parse(value: value);
 103
 1104            return true;
 105        }
 2106        catch
 107        {
 2108            result = null;
 109
 2110            return false;
 111        }
 3112    }
 113
 114    /// <summary>Implicitly converts a string into a <see cref="StyleFontWeight" /> instance.</summary>
 115    /// <param name="value">The string representation of the font-weight value.</param>
 116    /// <returns>A <see cref="StyleFontWeight" /> instance representing the provided value.</returns>
 117    /// <exception cref="AryArgumentException">
 118    /// Thrown when the provided string cannot be parsed into a valid
 119    /// <see cref="Kind" />.
 120    /// </exception>
 2121    public static implicit operator StyleFontWeight(string? value) => Parse(value: value);
 122
 123    /// <summary>Implicitly converts a <see cref="StyleFontWeight" /> instance to its string representation.</summary>
 124    /// <param name="value">The <see cref="StyleFontWeight" /> instance to convert.</param>
 125    /// <returns>
 126    /// The underlying CSS <c>font-weight</c> string value, or an empty string if <paramref name="value" /> is
 127    /// <see langword="null" />.
 128    /// </returns>
 2129    public static implicit operator string(StyleFontWeight? value) => (value?.Value).OrDefaultIfEmpty();
 130}