< Summary

Information
Class: Allyaria.Theming.StyleTypes.StyleString
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StyleString.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 53
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%22100%
Parse(...)100%11100%
TryParse(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%22100%

File(s)

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

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a simple CSS string value within the Allyaria theming system. Provides a strongly typed wrapper for any
 5/// arbitrary CSS-compatible string value, ensuring consistent handling and conversion across components.
 6/// </summary>
 7public sealed record StyleString : StyleValueBase
 8{
 9    /// <summary>Initializes a new instance of the <see cref="StyleString" /> record with an optional string value.</sum
 10    /// <param name="value">The string value to assign. If <see langword="null" />, an empty string is used.</param>
 11    public StyleString(string? value = "")
 20412        : base(value: value ?? string.Empty) { }
 13
 14    /// <summary>Parses the specified string into a <see cref="StyleString" /> instance.</summary>
 15    /// <param name="value">The string representation of the style value.</param>
 16    /// <returns>A new <see cref="StyleString" /> instance representing the provided value.</returns>
 717    public static StyleString Parse(string? value) => new(value: value);
 18
 19    /// <summary>Attempts to parse a string into a <see cref="StyleString" /> instance.</summary>
 20    /// <param name="value">The string representation of the style value to parse.</param>
 21    /// <param name="result">
 22    /// When this method returns, contains the parsed <see cref="StyleString" /> instance or <see langword="null" /> if 
 23    /// failed.
 24    /// </param>
 25    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 26    public static bool TryParse(string? value, out StyleString? result)
 27    {
 28        try
 29        {
 330            result = Parse(value: value);
 31
 232            return true;
 33        }
 134        catch
 35        {
 136            result = null;
 37
 138            return false;
 39        }
 340    }
 41
 42    /// <summary>Implicitly converts a string into a <see cref="StyleString" /> instance.</summary>
 43    /// <param name="value">The string value to convert.</param>
 44    /// <returns>A <see cref="StyleString" /> instance representing the provided string.</returns>
 245    public static implicit operator StyleString(string? value) => Parse(value: value);
 46
 47    /// <summary>Implicitly converts a <see cref="StyleString" /> instance to its underlying string representation.</sum
 48    /// <param name="value">The <see cref="StyleString" /> instance to convert.</param>
 49    /// <returns>
 50    /// The contained string value, or an empty string if <paramref name="value" /> is <see langword="null" />.
 51    /// </returns>
 452    public static implicit operator string(StyleString? value) => (value?.Value).OrDefaultIfEmpty();
 53}