| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="FileExtensionGroup.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Collections.Generic; |
| | | 9 | | using System.Linq; |
| | | 10 | | |
| | | 11 | | namespace MyNet.IO.FileExtensions; |
| | | 12 | | |
| | | 13 | | public 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 | | { |
| | 87 | 23 | | if (string.IsNullOrWhiteSpace(key)) |
| | 0 | 24 | | throw new ArgumentException("Key cannot be null or empty.", nameof(key)); |
| | | 25 | | |
| | | 26 | | Key = key; |
| | 87 | 27 | | Extensions = [.. extensions]; |
| | 87 | 28 | | } |
| | | 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> |
| | 78 | 41 | | 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> |
| | 6 | 52 | | public FileExtension? GetDefaultExtension() => Extensions.FirstOrDefault(); |
| | | 53 | | } |
| | | 54 | | |