| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="FileExtensionFilterBuilder.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.Collections.Generic; |
| | | 8 | | |
| | | 9 | | namespace MyNet.IO.FileExtensions; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Represents a builder for creating a file extension filter, which is used to generate file filters for file dialogs. |
| | | 13 | | /// </summary> |
| | | 14 | | public sealed class FileExtensionFilterBuilder |
| | | 15 | | { |
| | 6 | 16 | | private readonly List<FileExtensionGroup> _groups = []; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Adds a <see cref="FileExtensionGroup"/> to the builder. This method allows you to specify a group of file extens |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="group">The <see cref="FileExtensionGroup"/> to add to the builder.</param> |
| | | 22 | | /// <returns>The current instance of the <see cref="FileExtensionFilterBuilder"/>.</returns> |
| | | 23 | | public FileExtensionFilterBuilder Add(FileExtensionGroup group) |
| | | 24 | | { |
| | 6 | 25 | | _groups.Add(group); |
| | 6 | 26 | | return this; |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Adds a range of <see cref="FileExtensionGroup"/> items to the builder. This method allows you to specify multipl |
| | | 31 | | /// </summary> |
| | | 32 | | /// <param name="groups">The collection of <see cref="FileExtensionGroup"/> items to add to the builder.</param> |
| | | 33 | | /// <returns>The current instance of the <see cref="FileExtensionFilterBuilder"/>.</returns> |
| | | 34 | | public FileExtensionFilterBuilder AddRange(IEnumerable<FileExtensionGroup> groups) |
| | | 35 | | { |
| | 6 | 36 | | _groups.AddRange(groups); |
| | 6 | 37 | | return this; |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Builds the <see cref="FileExtensionFilter"/> using the added <see cref="FileExtensionGroup"/> items. This method |
| | | 42 | | /// </summary> |
| | | 43 | | /// <returns>A new instance of <see cref="FileExtensionFilter"/> containing the added groups.</returns> |
| | 6 | 44 | | public FileExtensionFilter Build() => new(_groups); |
| | | 45 | | } |
| | | 46 | | |