< Summary

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

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>font-style</c> value within the Allyaria theming system. Provides a strongly typed wrapper for
 5/// defining typographic style such as normal, italic, or oblique.
 6/// </summary>
 7public sealed record StyleFontStyle : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleFontStyle" /> record using the specified <see cref="Kind" /> v
 11    /// </summary>
 12    /// <param name="kind">The font style kind that determines how text is rendered.</param>
 13    public StyleFontStyle(Kind kind)
 2614        : base(value: kind.GetDescription()) { }
 15
 16    /// <summary>Defines the supported CSS <c>font-style</c> property values.</summary>
 17    public enum Kind
 18    {
 19        /// <summary>Renders text in an italicized form, typically using a distinct italic font face.</summary>
 20        [Description(description: "italic")]
 21        Italic,
 22
 23        /// <summary>Renders text normally without slanting or italics.</summary>
 24        [Description(description: "normal")]
 25        Normal,
 26
 27        /// <summary>Renders text slanted, typically when a true italic face is not available.</summary>
 28        [Description(description: "oblique")]
 29        Oblique
 30    }
 31
 32    /// <summary>
 33    /// Parses a string representation of a CSS <c>font-style</c> value into a <see cref="StyleFontStyle" /> instance.
 34    /// </summary>
 35    /// <param name="value">The string representation of the font-style value.</param>
 36    /// <returns>A new <see cref="StyleFontStyle" /> instance representing the parsed value.</returns>
 37    /// <exception cref="AryArgumentException">
 38    /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />.
 39    /// </exception>
 40    public static StyleFontStyle Parse(string? value)
 1041        => value.TryParseEnum<Kind>(result: out var kind)
 1042            ? new StyleFontStyle(kind: kind)
 1043            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 44
 45    /// <summary>Attempts to parse a string into a <see cref="StyleFontStyle" /> instance.</summary>
 46    /// <param name="value">The string representation of the font-style value to parse.</param>
 47    /// <param name="result">
 48    /// When this method returns, contains the parsed <see cref="StyleFontStyle" /> instance or <see langword="null" /> 
 49    /// parsing failed.
 50    /// </param>
 51    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 52    public static bool TryParse(string? value, out StyleFontStyle? result)
 53    {
 54        try
 55        {
 356            result = Parse(value: value);
 57
 158            return true;
 59        }
 260        catch
 61        {
 262            result = null;
 63
 264            return false;
 65        }
 366    }
 67
 68    /// <summary>Implicitly converts a string into a <see cref="StyleFontStyle" /> instance.</summary>
 69    /// <param name="value">The string representation of the font-style value.</param>
 70    /// <returns>A <see cref="StyleFontStyle" /> instance representing the provided value.</returns>
 71    /// <exception cref="AryArgumentException">
 72    /// Thrown when the provided string cannot be parsed into a valid
 73    /// <see cref="Kind" />.
 74    /// </exception>
 275    public static implicit operator StyleFontStyle(string? value) => Parse(value: value);
 76
 77    /// <summary>Implicitly converts a <see cref="StyleFontStyle" /> instance to its string representation.</summary>
 78    /// <param name="value">The <see cref="StyleFontStyle" /> instance to convert.</param>
 79    /// <returns>
 80    /// The underlying CSS <c>font-style</c> string value, or an empty string if <paramref name="value" /> is
 81    /// <see langword="null" />.
 82    /// </returns>
 283    public static implicit operator string(StyleFontStyle? value) => (value?.Value).OrDefaultIfEmpty();
 84}