#nullable enable using System.Collections.Generic; using System.Linq; namespace BizHawk.Client.Common { public sealed class FilesystemFilterSet { public readonly IReadOnlyCollection Filters; public FilesystemFilterSet(params FilesystemFilter[] filters) { Filters = filters; } /// appends All Files entry (calls with ), return value is a valid Filter for Save-/OpenFileDialog public override string ToString() => ToString(true); /// call other overload to prepend combined entry, return value is a valid Filter for Save-/OpenFileDialog public string ToString(bool addAllFilesEntry) => addAllFilesEntry ? $"{ToString(false)}|{FilesystemFilter.AllFilesEntry}" : string.Join("|", Filters.Select(filter => filter.ToString())); /// call other overload (omit ) to not prepend combined entry, return value is a valid Filter for Save-/OpenFileDialog public string ToString(string combinedEntryDesc, bool addAllFilesEntry = true) => $"{FilesystemFilter.SerializeEntry(combinedEntryDesc, Filters.SelectMany(filter => filter.Extensions).Distinct().OrderBy(s => s))}|{ToString(addAllFilesEntry)}"; public static readonly FilesystemFilterSet Screenshots = new FilesystemFilterSet(FilesystemFilter.PNGs, new FilesystemFilter(".bmp Files", new[] { "bmp" })); } }