< Summary

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

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>text-transform</c> value within the Allyaria theming system. Provides a strongly typed wrapper f
 5/// defining text casing transformations applied to content.
 6/// </summary>
 7public sealed record StyleTextTransform : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleTextTransform" /> record using the specified <see cref="Kind" 
 11    /// value.
 12    /// </summary>
 13    /// <param name="kind">The text transformation behavior to represent.</param>
 14    public StyleTextTransform(Kind kind)
 3215        : base(value: kind.GetDescription()) { }
 16
 17    /// <summary>Defines the supported CSS <c>text-transform</c> property values.</summary>
 18    public enum Kind
 19    {
 20        /// <summary>Transforms the first character of each word to uppercase while leaving the rest unchanged.</summary
 21        [Description(description: "capitalize")]
 22        Capitalize,
 23
 24        /// <summary>Transforms all characters to lowercase.</summary>
 25        [Description(description: "lowercase")]
 26        Lowercase,
 27
 28        /// <summary>Prevents any case transformation; text appears as originally authored.</summary>
 29        [Description(description: "none")]
 30        None,
 31
 32        /// <summary>Transforms all characters to uppercase.</summary>
 33        [Description(description: "uppercase")]
 34        Uppercase
 35    }
 36
 37    /// <summary>
 38    /// Parses a string representation of a CSS <c>text-transform</c> value into a <see cref="StyleTextTransform" /> ins
 39    /// </summary>
 40    /// <param name="value">The string representation of the text-transform value.</param>
 41    /// <returns>A new <see cref="StyleTextTransform" /> instance representing the parsed value.</returns>
 42    /// <exception cref="AryArgumentException">
 43    /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />.
 44    /// </exception>
 45    public static StyleTextTransform Parse(string? value)
 1146        => value.TryParseEnum<Kind>(result: out var kind)
 1147            ? new StyleTextTransform(kind: kind)
 1148            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 49
 50    /// <summary>Attempts to parse a string into a <see cref="StyleTextTransform" /> instance.</summary>
 51    /// <param name="value">The string representation of the text-transform value to parse.</param>
 52    /// <param name="result">
 53    /// When this method returns, contains the parsed <see cref="StyleTextTransform" /> instance or <see langword="null"
 54    /// parsing failed.
 55    /// </param>
 56    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 57    public static bool TryParse(string? value, out StyleTextTransform? result)
 58    {
 59        try
 60        {
 361            result = Parse(value: value);
 62
 163            return true;
 64        }
 265        catch
 66        {
 267            result = null;
 68
 269            return false;
 70        }
 371    }
 72
 73    /// <summary>Implicitly converts a string into a <see cref="StyleTextTransform" /> instance.</summary>
 74    /// <param name="value">The string representation of the text-transform value.</param>
 75    /// <returns>A <see cref="StyleTextTransform" /> instance representing the provided value.</returns>
 76    /// <exception cref="AryArgumentException">
 77    /// Thrown when the provided string cannot be parsed into a valid
 78    /// <see cref="Kind" />.
 79    /// </exception>
 280    public static implicit operator StyleTextTransform(string? value) => Parse(value: value);
 81
 82    /// <summary>Implicitly converts a <see cref="StyleTextTransform" /> instance to its string representation.</summary
 83    /// <param name="value">The <see cref="StyleTextTransform" /> instance to convert.</param>
 84    /// <returns>
 85    /// The underlying CSS <c>text-transform</c> string value, or an empty string if <paramref name="value" /> is
 86    /// <see langword="null" />.
 87    /// </returns>
 288    public static implicit operator string(StyleTextTransform? value) => (value?.Value).OrDefaultIfEmpty();
 89}