< Summary

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

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>color</c> value within the Allyaria theming system. Provides a strongly typed wrapper around col
 5/// values supporting parsing and conversion to and from <see cref="HexColor" /> and string representations.
 6/// </summary>
 7public sealed record StyleColor : StyleValueBase
 8{
 9    /// <summary>Initializes a new instance of the <see cref="StyleColor" /> record using a string color value.</summary
 10    /// <param name="value">The color value as a string, typically in hexadecimal, RGB(A), or named CSS color format.</p
 11    /// <exception cref="ArgumentException">
 12    /// Thrown when the provided <paramref name="value" /> cannot be parsed into a valid <see cref="HexColor" />.
 13    /// </exception>
 14    public StyleColor(string value)
 2511715        : this(color: new HexColor(value: value)) { }
 16
 17    /// <summary>
 18    /// Initializes a new instance of the <see cref="StyleColor" /> record using a <see cref="HexColor" /> instance.
 19    /// </summary>
 20    /// <param name="color">The <see cref="HexColor" /> instance to represent.</param>
 21    public StyleColor(HexColor color)
 1803122        : base(value: color.ToString())
 1803123        => Color = color;
 24
 25    /// <summary>Gets the strongly typed <see cref="HexColor" /> value represented by this instance.</summary>
 1748326    public HexColor Color { get; }
 27
 28    /// <summary>Parses a string representation of a CSS color into a <see cref="StyleColor" /> instance.</summary>
 29    /// <param name="value">The string representation of the color to parse. Supports hexadecimal, RGB(A), and named col
 30    /// <returns>A new <see cref="StyleColor" /> instance representing the parsed color.</returns>
 31    /// <exception cref="ArgumentException">
 32    /// Thrown when the provided <paramref name="value" /> cannot be parsed into a valid
 33    /// color format.
 34    /// </exception>
 735    public static StyleColor Parse(string? value) => new(value: value ?? string.Empty);
 36
 37    /// <summary>Attempts to parse a string representation of a CSS color into a <see cref="StyleColor" /> instance.</su
 38    /// <param name="value">The string representation of the color value to parse.</param>
 39    /// <param name="result">
 40    /// When this method returns, contains the parsed <see cref="StyleColor" /> instance or <see langword="null" /> if p
 41    /// failed.
 42    /// </param>
 43    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 44    public static bool TryParse(string? value, out StyleColor? result)
 45    {
 46        try
 47        {
 248            result = Parse(value: value);
 49
 150            return true;
 51        }
 152        catch
 53        {
 154            result = null;
 55
 156            return false;
 57        }
 258    }
 59
 60    /// <summary>Implicitly converts a string value into a <see cref="StyleColor" /> instance.</summary>
 61    /// <param name="value">The string representation of the color value.</param>
 62    /// <returns>A <see cref="StyleColor" /> instance representing the provided value.</returns>
 63    /// <exception cref="ArgumentException">Thrown when the provided string cannot be parsed into a valid color format.<
 264    public static implicit operator StyleColor(string? value) => Parse(value: value);
 65
 66    /// <summary>Implicitly converts a <see cref="StyleColor" /> instance to its string representation.</summary>
 67    /// <param name="value">The <see cref="StyleColor" /> instance to convert.</param>
 68    /// <returns>
 69    /// The CSS string representation of the color (typically in hex format), or an empty string if <paramref name="valu
 70    /// is <see langword="null" />.
 71    /// </returns>
 272    public static implicit operator string(StyleColor? value) => (value?.Value).OrDefaultIfEmpty();
 73}