< Summary

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

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>text-align</c> value within the Allyaria theming system. Provides a strongly typed wrapper for
 5/// defining horizontal text alignment behavior in CSS.
 6/// </summary>
 7public sealed record StyleTextAlign : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleTextAlign" /> record using the specified <see cref="Kind" /> v
 11    /// </summary>
 12    /// <param name="kind">The text alignment type to represent.</param>
 13    public StyleTextAlign(Kind kind)
 3614        : base(value: kind.GetDescription()) { }
 15
 16    /// <summary>Defines the supported CSS <c>text-align</c> property values.</summary>
 17    public enum Kind
 18    {
 19        /// <summary>Centers the inline content within the line box.</summary>
 20        [Description(description: "center")]
 21        Center,
 22
 23        /// <summary>
 24        /// Aligns the inline content to the end edge of the line box based on the document’s writing direction (right f
 25        /// left for RTL).
 26        /// </summary>
 27        [Description(description: "end")]
 28        End,
 29
 30        /// <summary>Justifies text so that each line (except the last) is stretched to fill the container width.</summa
 31        [Description(description: "justify")]
 32        Justify,
 33
 34        /// <summary>Inherits alignment from the parent element’s text alignment value.</summary>
 35        [Description(description: "match-parent")]
 36        MatchParent,
 37
 38        /// <summary>
 39        /// Aligns text to the start edge of the line box based on the document’s writing direction (left for LTR, right
 40        /// </summary>
 41        [Description(description: "start")]
 42        Start
 43    }
 44
 45    /// <summary>
 46    /// Parses a string representation of a CSS <c>text-align</c> value into a <see cref="StyleTextAlign" /> instance.
 47    /// </summary>
 48    /// <param name="value">The string representation of the text-align value.</param>
 49    /// <returns>A new <see cref="StyleTextAlign" /> instance representing the parsed value.</returns>
 50    /// <exception cref="AryArgumentException">
 51    /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />.
 52    /// </exception>
 53    public static StyleTextAlign Parse(string? value)
 1254        => value.TryParseEnum<Kind>(result: out var kind)
 1255            ? new StyleTextAlign(kind: kind)
 1256            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 57
 58    /// <summary>Attempts to parse a string into a <see cref="StyleTextAlign" /> instance.</summary>
 59    /// <param name="value">The string representation of the text-align value to parse.</param>
 60    /// <param name="result">
 61    /// When this method returns, contains the parsed <see cref="StyleTextAlign" /> instance or <see langword="null" /> 
 62    /// parsing failed.
 63    /// </param>
 64    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 65    public static bool TryParse(string? value, out StyleTextAlign? result)
 66    {
 67        try
 68        {
 369            result = Parse(value: value);
 70
 171            return true;
 72        }
 273        catch
 74        {
 275            result = null;
 76
 277            return false;
 78        }
 379    }
 80
 81    /// <summary>Implicitly converts a string into a <see cref="StyleTextAlign" /> instance.</summary>
 82    /// <param name="value">The string representation of the text-align value.</param>
 83    /// <returns>A <see cref="StyleTextAlign" /> instance representing the provided value.</returns>
 84    /// <exception cref="AryArgumentException">
 85    /// Thrown when the provided string cannot be parsed into a valid
 86    /// <see cref="Kind" />.
 87    /// </exception>
 288    public static implicit operator StyleTextAlign(string? value) => Parse(value: value);
 89
 90    /// <summary>Implicitly converts a <see cref="StyleTextAlign" /> instance to its string representation.</summary>
 91    /// <param name="value">The <see cref="StyleTextAlign" /> instance to convert.</param>
 92    /// <returns>
 93    /// The underlying CSS <c>text-align</c> string value, or an empty string if <paramref name="value" /> is
 94    /// <see langword="null" />.
 95    /// </returns>
 296    public static implicit operator string(StyleTextAlign? value) => (value?.Value).OrDefaultIfEmpty();
 97}