| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | |
| | | 4 | | namespace NexusLabs.Needlr.Generators; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Configuration options for diagnostic file generation. |
| | | 8 | | /// </summary> |
| | | 9 | | internal sealed class DiagnosticOptions |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Whether diagnostics are enabled. |
| | | 13 | | /// </summary> |
| | 441 | 14 | | public bool Enabled { get; } |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Directory path where diagnostic files will be written. |
| | | 18 | | /// </summary> |
| | 97 | 19 | | public string OutputPath { get; } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Optional filter - only include types whose fully qualified names are in this set. |
| | | 23 | | /// If empty, all types are included. |
| | | 24 | | /// </summary> |
| | 394 | 25 | | public HashSet<string> TypeFilter { get; } |
| | | 26 | | |
| | 450 | 27 | | public DiagnosticOptions(bool enabled, string outputPath, HashSet<string> typeFilter) |
| | | 28 | | { |
| | 450 | 29 | | Enabled = enabled; |
| | 450 | 30 | | OutputPath = outputPath ?? string.Empty; |
| | 450 | 31 | | TypeFilter = typeFilter ?? new HashSet<string>(StringComparer.Ordinal); |
| | 450 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Parses diagnostic options from MSBuild property values. |
| | | 36 | | /// </summary> |
| | | 37 | | public static DiagnosticOptions Parse(string? enabledValue, string? outputPath, string? filterValue) |
| | | 38 | | { |
| | 450 | 39 | | var enabled = ParseBool(enabledValue); |
| | 450 | 40 | | var path = string.IsNullOrWhiteSpace(outputPath) ? string.Empty : outputPath!.Trim(); |
| | 450 | 41 | | var filter = ParseFilter(filterValue); |
| | | 42 | | |
| | 450 | 43 | | return new DiagnosticOptions(enabled, path, filter); |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | private static bool ParseBool(string? value) |
| | | 47 | | { |
| | 450 | 48 | | if (string.IsNullOrWhiteSpace(value)) |
| | 336 | 49 | | return false; |
| | | 50 | | |
| | 114 | 51 | | return value!.Equals("true", StringComparison.OrdinalIgnoreCase) || |
| | 114 | 52 | | value.Equals("1", StringComparison.Ordinal); |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | private static HashSet<string> ParseFilter(string? value) |
| | | 56 | | { |
| | 450 | 57 | | var result = new HashSet<string>(StringComparer.Ordinal); |
| | | 58 | | |
| | 450 | 59 | | if (string.IsNullOrWhiteSpace(value)) |
| | 435 | 60 | | return result; |
| | | 61 | | |
| | 15 | 62 | | var parts = value!.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); |
| | 76 | 63 | | foreach (var part in parts) |
| | | 64 | | { |
| | 23 | 65 | | var trimmed = part.Trim(); |
| | 23 | 66 | | if (!string.IsNullOrEmpty(trimmed)) |
| | | 67 | | { |
| | 23 | 68 | | result.Add(trimmed); |
| | | 69 | | } |
| | | 70 | | } |
| | | 71 | | |
| | 15 | 72 | | return result; |
| | | 73 | | } |
| | | 74 | | } |