| | 1 | | // Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT |
| | 2 | | using System.Text.Json.Serialization; |
| | 3 | |
|
| | 4 | | namespace DotNetApiDiff.Models.Configuration; |
| | 5 | |
|
| | 6 | | /// <summary> |
| | 7 | | /// Configuration for filtering types and namespaces during API comparison |
| | 8 | | /// </summary> |
| | 9 | | public class FilterConfiguration |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// List of namespaces to include in the comparison (if empty, all namespaces are included) |
| | 13 | | /// </summary> |
| | 14 | | [JsonPropertyName("includeNamespaces")] |
| 331 | 15 | | public List<string> IncludeNamespaces { get; set; } = new List<string>(); |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// List of namespaces to exclude from the comparison |
| | 19 | | /// </summary> |
| | 20 | | [JsonPropertyName("excludeNamespaces")] |
| 317 | 21 | | public List<string> ExcludeNamespaces { get; set; } = new List<string>(); |
| | 22 | |
|
| | 23 | | /// <summary> |
| | 24 | | /// List of type name patterns to include in the comparison (if empty, all types are included) |
| | 25 | | /// </summary> |
| | 26 | | [JsonPropertyName("includeTypes")] |
| 317 | 27 | | public List<string> IncludeTypes { get; set; } = new List<string>(); |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// List of type name patterns to exclude from the comparison |
| | 31 | | /// </summary> |
| | 32 | | [JsonPropertyName("excludeTypes")] |
| 316 | 33 | | public List<string> ExcludeTypes { get; set; } = new List<string>(); |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Whether to include internal types in the comparison |
| | 37 | | /// </summary> |
| | 38 | | [JsonPropertyName("includeInternals")] |
| 293 | 39 | | public bool IncludeInternals { get; set; } = false; |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Whether to include compiler-generated types in the comparison |
| | 43 | | /// </summary> |
| | 44 | | [JsonPropertyName("includeCompilerGenerated")] |
| 288 | 45 | | public bool IncludeCompilerGenerated { get; set; } = false; |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// Creates a default filter configuration |
| | 49 | | /// </summary> |
| | 50 | | /// <returns>A default filter configuration</returns> |
| | 51 | | public static FilterConfiguration CreateDefault() |
| 70 | 52 | | { |
| 70 | 53 | | return new FilterConfiguration |
| 70 | 54 | | { |
| 70 | 55 | | IncludeNamespaces = new List<string>(), |
| 70 | 56 | | ExcludeNamespaces = new List<string>(), |
| 70 | 57 | | IncludeTypes = new List<string>(), |
| 70 | 58 | | ExcludeTypes = new List<string>(), |
| 70 | 59 | | IncludeInternals = false, |
| 70 | 60 | | IncludeCompilerGenerated = false |
| 70 | 61 | | }; |
| 70 | 62 | | } |
| | 63 | |
|
| | 64 | | /// <summary> |
| | 65 | | /// Validates the filter configuration |
| | 66 | | /// </summary> |
| | 67 | | /// <returns>True if valid, false otherwise</returns> |
| | 68 | | public bool IsValid() |
| 32 | 69 | | { |
| | 70 | | // All patterns should be non-empty |
| 32 | 71 | | if (IncludeNamespaces.Any(string.IsNullOrWhiteSpace) || |
| 32 | 72 | | ExcludeNamespaces.Any(string.IsNullOrWhiteSpace) || |
| 32 | 73 | | IncludeTypes.Any(string.IsNullOrWhiteSpace) || |
| 32 | 74 | | ExcludeTypes.Any(string.IsNullOrWhiteSpace)) |
| 4 | 75 | | { |
| 4 | 76 | | return false; |
| | 77 | | } |
| | 78 | |
|
| 28 | 79 | | return true; |
| 32 | 80 | | } |
| | 81 | | } |