< Summary

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

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>alignment-baseline</c> value used within the Allyaria theming system. Provides a strongly typed
 5/// wrapper around standard CSS alignment-baseline keywords.
 6/// </summary>
 7public sealed record StyleAlignmentBaseline : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleAlignmentBaseline" /> record with the specified baseline align
 11    /// kind.
 12    /// </summary>
 13    /// <param name="kind">The baseline alignment kind to represent.</param>
 14    public StyleAlignmentBaseline(Kind kind)
 5415        : base(value: kind.GetDescription()) { }
 16
 17    /// <summary>Defines the supported CSS <c>alignment-baseline</c> values.</summary>
 18    public enum Kind
 19    {
 20        /// <summary>
 21        /// Aligns the element with the alphabetic baseline of its parent. Typically used for Latin-based scripts.
 22        /// </summary>
 23        [Description(description: "alphabetic")]
 24        Alphabetic,
 25
 26        /// <summary>Aligns the element with the dominant baseline of its parent.</summary>
 27        [Description(description: "baseline")]
 28        Baseline,
 29
 30        /// <summary>
 31        /// Aligns the element so that the geometric center of its box aligns with the parent's alignment baseline.
 32        /// </summary>
 33        [Description(description: "central")]
 34        Central,
 35
 36        /// <summary>Aligns the element with the ideographic baseline used for East Asian text.</summary>
 37        [Description(description: "ideographic")]
 38        Ideographic,
 39
 40        /// <summary>Aligns the element with the mathematical baseline, used for math formulas or similar content.</summ
 41        [Description(description: "mathematical")]
 42        Mathematical,
 43
 44        /// <summary>Aligns the element with the vertical middle of its parent’s box.</summary>
 45        [Description(description: "middle")]
 46        Middle,
 47
 48        /// <summary>Aligns the element with the bottom of the parent's text content area.</summary>
 49        [Description(description: "text-bottom")]
 50        TextBottom,
 51
 52        /// <summary>Aligns the element with the top of the parent's text content area.</summary>
 53        [Description(description: "text-top")]
 54        TextTop
 55    }
 56
 57    /// <summary>
 58    /// Parses a string representation of a CSS <c>alignment-baseline</c> value into a <see cref="StyleAlignmentBaseline
 59    /// instance.
 60    /// </summary>
 61    /// <param name="value">The string representation of the alignment-baseline value.</param>
 62    /// <returns>A new <see cref="StyleAlignmentBaseline" /> instance representing the parsed value.</returns>
 63    /// <exception cref="AryArgumentException">
 64    /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />.
 65    /// </exception>
 66    public static StyleAlignmentBaseline Parse(string? value)
 1567        => value.TryParseEnum<Kind>(result: out var kind)
 1568            ? new StyleAlignmentBaseline(kind: kind)
 1569            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 70
 71    /// <summary>Attempts to parse a string into a <see cref="StyleAlignmentBaseline" /> instance.</summary>
 72    /// <param name="value">The string representation of the alignment-baseline value to parse.</param>
 73    /// <param name="result">
 74    /// When this method returns, contains the parsed <see cref="StyleAlignmentBaseline" /> instance or <see langword="n
 75    /// if parsing failed.
 76    /// </param>
 77    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 78    public static bool TryParse(string? value, out StyleAlignmentBaseline? result)
 79    {
 80        try
 81        {
 382            result = Parse(value: value);
 83
 184            return true;
 85        }
 286        catch
 87        {
 288            result = null;
 89
 290            return false;
 91        }
 392    }
 93
 94    /// <summary>Implicitly converts a string into a <see cref="StyleAlignmentBaseline" /> instance.</summary>
 95    /// <param name="value">The string value representing the baseline alignment.</param>
 96    /// <returns>A <see cref="StyleAlignmentBaseline" /> instance equivalent to the provided value.</returns>
 97    /// <exception cref="AryArgumentException">Thrown when the string cannot be parsed into a valid alignment baseline k
 298    public static implicit operator StyleAlignmentBaseline(string? value) => Parse(value: value);
 99
 100    /// <summary>Implicitly converts a <see cref="StyleAlignmentBaseline" /> instance into its string value.</summary>
 101    /// <param name="value">The <see cref="StyleAlignmentBaseline" /> instance to convert.</param>
 102    /// <returns>
 103    /// The underlying CSS <c>alignment-baseline</c> string value, or an empty string if <paramref name="value" /> is
 104    /// <see langword="null" />.
 105    /// </returns>
 2106    public static implicit operator string(StyleAlignmentBaseline? value) => (value?.Value).OrDefaultIfEmpty();
 107}