< Summary

Information
Class: MyNet.IO.FileExtensions.FileExtension
Assembly: MyNet.IO
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.IO/FileExtensions/FileExtension.cs
Tag: 323_28699572109
Line coverage
88%
Covered lines: 8
Uncovered lines: 1
Coverable lines: 9
Total lines: 65
Line coverage: 88.8%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%2275%
Normalize(...)100%22100%
ToString()100%11100%
Equals(...)50%22100%
GetHashCode()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.IO/FileExtensions/FileExtension.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="FileExtension.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Globalization;
 9
 10namespace MyNet.IO.FileExtensions;
 11
 12/// <summary>
 13/// Represents a file extension, ensuring it is normalized (lowercase and starts with a dot).
 14/// </summary>
 15public sealed class FileExtension
 16{
 17    /// <summary>
 18    /// Initializes a new instance of the <see cref="FileExtension"/> class with the specified extension value. The cons
 19    /// </summary>
 20    /// <param name="value">The file extension value.</param>
 21    /// <exception cref="ArgumentException">Thrown when the <paramref name="value"/> is null, empty, or consists only of
 22    public FileExtension(string value)
 23    {
 14724        if (string.IsNullOrWhiteSpace(value))
 025            throw new ArgumentException("Extension cannot be null or empty.", nameof(value));
 26
 14727        Value = Normalize(value);
 14728    }
 29
 30    /// <summary>
 31    /// Gets the normalized file extension value. The value is stored in lowercase and starts with a dot, ensuring consi
 32    /// </summary>
 33    public string Value { get; }
 34
 35    /// <summary>
 36    /// Normalizes the file extension by trimming whitespace, converting it to lowercase, and ensuring it starts with a 
 37    /// </summary>
 38    /// <param name="extension">The file extension to normalize.</param>
 39    /// <returns>The normalized file extension.</returns>
 40    private static string Normalize(string extension)
 41    {
 14742        extension = extension.Trim().ToLower(CultureInfo.CurrentCulture);
 14743        return extension.StartsWith('.') ? extension : $".{extension}";
 44    }
 45
 46    /// <summary>
 47    /// Returns a string representation of the file extension, which is the normalized value. This method overrides the 
 48    /// </summary>
 49    /// <returns>The normalized file extension value.</returns>
 350    public override string ToString() => Value;
 51
 52    /// <summary>
 53    /// Determines whether the specified object is equal to the current file extension. Two <see cref="FileExtension"/> 
 54    /// </summary>
 55    /// <param name="obj">The object to compare with the current file extension.</param>
 56    /// <returns><c>true</c> if the specified object is equal to the current file extension; otherwise, <c>false</c>.</r
 357    public override bool Equals(object? obj) => obj is FileExtension other && Value == other.Value;
 58
 59    /// <summary>
 60    /// Returns a hash code for the file extension, which is based on the normalized value. This method overrides the de
 61    /// </summary>
 62    /// <returns>A hash code for the current file extension.</returns>
 663    public override int GetHashCode() => Value.GetHashCode(StringComparison.OrdinalIgnoreCase);
 64}
 65