< Summary

Information
Class: MyNet.IO.FileExtensions.FileExtensionGroup
Assembly: MyNet.IO
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.IO/FileExtensions/FileExtensionGroup.cs
Tag: 323_28699572109
Line coverage
83%
Covered lines: 5
Uncovered lines: 1
Coverable lines: 6
Total lines: 54
Line coverage: 83.3%
Branch coverage
0%
Covered branches: 0
Total branches: 1
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)0%1175%
Create(...)100%11100%
GetDefaultExtension()100%11100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="FileExtensionGroup.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9using System.Linq;
 10
 11namespace MyNet.IO.FileExtensions;
 12
 13public sealed class FileExtensionGroup
 14{
 15    /// <summary>
 16    /// Initializes a new instance of the <see cref="FileExtensionGroup"/> class with the specified key and extensions. 
 17    /// </summary>
 18    /// <param name="key">The key representing the extension group.</param>
 19    /// <param name="extensions">The file extensions in the group.</param>
 20    /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is null, empty, or consists only of w
 21    public FileExtensionGroup(string key, IEnumerable<FileExtension> extensions)
 22    {
 8723        if (string.IsNullOrWhiteSpace(key))
 024            throw new ArgumentException("Key cannot be null or empty.", nameof(key));
 25
 26        Key = key;
 8727        Extensions = [.. extensions];
 8728    }
 29
 30    /// <summary>
 31    /// Gets the key representing the extension group. This key can be used to translate the name of the extension group
 32    /// </summary>
 33    public string Key { get; }
 34
 35    /// <summary>
 36    /// Creates a new <see cref="FileExtensionGroup"/> with the specified key and extensions.
 37    /// </summary>
 38    /// <param name="key">The key representing the extension group.</param>
 39    /// <param name="extensions">The file extensions in the group.</param>
 40    /// <returns>A new <see cref="FileExtensionGroup"/> instance.</returns>
 7841    public static FileExtensionGroup Create(string key, params string[] extensions) => new(key, extensions.Select(x => n
 42
 43    /// <summary>
 44    /// Gets the list of file extensions associated with the extension group. These extensions are used to filter files 
 45    /// </summary>
 46    public IReadOnlyList<FileExtension> Extensions { get; }
 47
 48    /// <summary>
 49    /// Gets the default file extension for the extension group. This is typically the first extension in the list.
 50    /// </summary>
 51    /// <returns>The default file extension, or <c>null</c> if the group has no extensions.</returns>
 652    public FileExtension? GetDefaultExtension() => Extensions.FirstOrDefault();
 53}
 54