From 1ea7acd799c9474d212cc776a7147fb55c49030e Mon Sep 17 00:00:00 2001 From: Phillip Hoff Date: Sun, 11 Oct 2026 11:21:44 -0700 Subject: [PATCH] Fix scripts to build against the IReadOnlyList public API The library collections moved from ImmutableArray to IReadOnlyList, so the file-based scripts under scripts/ no longer compiled. - Replace IsDefaultOrEmpty/Length with Count. The list properties are non-nullable and default to [], so Count > 0 is a complete check. - Drop inline @9.0.0 versions from #:package directives, which conflict with Central Package Management, and add a PackageVersion for Microsoft.Extensions.Logging.Console. - Use AddSimpleConsole for IncludeScopes; the ConsoleLoggerOptions property is obsolete and warnings are errors. - Opt BuildChartIndex out of the file-based-app PublishAot default, which flagged its reflection-based JSON serialization. --- Directory.Packages.props | 1 + scripts/BuildChartIndex.cs | 1 + scripts/DumpCatalog.cs | 26 +++++++-------- scripts/DumpChart.cs | 66 +++++++++++++++++++------------------- scripts/ReadCatalog.cs | 2 +- scripts/ReadCatalogS57.cs | 18 +++++------ 6 files changed, 58 insertions(+), 56 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index f280261..fb1dcee 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -17,6 +17,7 @@ + diff --git a/scripts/BuildChartIndex.cs b/scripts/BuildChartIndex.cs index 586f32e..95c8089 100644 --- a/scripts/BuildChartIndex.cs +++ b/scripts/BuildChartIndex.cs @@ -2,6 +2,7 @@ #:project ../src/EncDotNet.S57/EncDotNet.S57.csproj #:project ../src/EncDotNet.Noaa/EncDotNet.Noaa.csproj +#:property PublishAot=false using System.Text.Json; using EncDotNet.Noaa; diff --git a/scripts/DumpCatalog.cs b/scripts/DumpCatalog.cs index 670736e..2df65c9 100644 --- a/scripts/DumpCatalog.cs +++ b/scripts/DumpCatalog.cs @@ -1,7 +1,7 @@ #!/usr/bin/env dotnet run -#:package Microsoft.Extensions.Logging@9.0.0 -#:package Microsoft.Extensions.Logging.Console@9.0.0 +#:package Microsoft.Extensions.Logging +#:package Microsoft.Extensions.Logging.Console #:project ../src/EncDotNet.S57/EncDotNet.S57.csproj @@ -58,7 +58,7 @@ ddr = Iso8211DataDescriptiveRecordReader.Read(iso8211Doc.DataDescriptiveRecord); } -for (int r = 0; r < iso8211Doc.Records.Length; r++) +for (int r = 0; r < iso8211Doc.Records.Count; r++) { var record = iso8211Doc.Records[r]; var leader = record.Leader; @@ -75,12 +75,12 @@ Console.WriteLine($"│ Base Address : {leader.BaseAddressOfFieldArea}"); Console.WriteLine($"│ Ext Char Set : {leader.ExtendedCharacterSetIndicator}"); Console.WriteLine($"│ Entry Map : tag={leader.SizeOfFieldTagField} len={leader.SizeOfFieldLengthField} pos={leader.SizeOfFieldPositionField}"); - Console.WriteLine($"│ Directory Entries : {record.Directory.Length}"); - Console.WriteLine($"│ Fields : {record.Fields.Length}"); + Console.WriteLine($"│ Directory Entries : {record.Directory.Count}"); + Console.WriteLine($"│ Fields : {record.Fields.Count}"); Console.WriteLine("│"); // Directory entries - if (record.Directory.Length > 0) + if (record.Directory.Count > 0) { Console.WriteLine("│ ┌─ Directory ────────────────────────────────────────"); foreach (var entry in record.Directory) @@ -92,7 +92,7 @@ } // Fields with hex dump - for (int f = 0; f < record.Fields.Length; f++) + for (int f = 0; f < record.Fields.Count; f++) { var field = record.Fields[f]; Console.WriteLine($"│ ┌─ Field {f}: Tag = \"{field.Tag}\" ({field.Data.Length} bytes) ──────"); @@ -137,7 +137,7 @@ Console.WriteLine($"│ Format Controls: {fieldDef.FormatControls}"); Console.WriteLine($"│ Repeating Group: {(fieldDef.HasRepeatingGroup ? $"Yes (from index {fieldDef.RepeatingSubfieldStartIndex})" : "No")}"); - if (!fieldDef.SubfieldDefinitions.IsDefaultOrEmpty) + if (fieldDef.SubfieldDefinitions.Count > 0) { Console.WriteLine("│ Subfields:"); foreach (var sf in fieldDef.SubfieldDefinitions) @@ -153,10 +153,10 @@ } // --- Catalog Entries --- -Console.WriteLine($"┌─── Catalog Entries ({catalog.Entries.Length} total) ──────────────────────────"); +Console.WriteLine($"┌─── Catalog Entries ({catalog.Entries.Count} total) ──────────────────────────"); Console.WriteLine("│"); -for (int i = 0; i < catalog.Entries.Length; i++) +for (int i = 0; i < catalog.Entries.Count; i++) { var entry = catalog.Entries[i]; @@ -196,9 +196,9 @@ Console.WriteLine("╔══════════════════════════════════════════════════════════════════════╗"); Console.WriteLine("║ SUMMARY ║"); Console.WriteLine("╚══════════════════════════════════════════════════════════════════════╝"); -Console.WriteLine($" ISO 8211 Records : {iso8211Doc.Records.Length}"); -Console.WriteLine($" DDR Fields : {(ddr is not null ? ddr.FieldDefinitions.Length : 0)}"); -Console.WriteLine($" Catalog Entries : {catalog.Entries.Length}"); +Console.WriteLine($" ISO 8211 Records : {iso8211Doc.Records.Count}"); +Console.WriteLine($" DDR Fields : {(ddr is not null ? ddr.FieldDefinitions.Count : 0)}"); +Console.WriteLine($" Catalog Entries : {catalog.Entries.Count}"); Console.WriteLine(); // ============================================================================ diff --git a/scripts/DumpChart.cs b/scripts/DumpChart.cs index 5ffda06..685687a 100644 --- a/scripts/DumpChart.cs +++ b/scripts/DumpChart.cs @@ -1,7 +1,7 @@ #!/usr/bin/env dotnet run -#:package Microsoft.Extensions.Logging@9.0.0 -#:package Microsoft.Extensions.Logging.Console@9.0.0 +#:package Microsoft.Extensions.Logging +#:package Microsoft.Extensions.Logging.Console #:project ../src/EncDotNet.S57/EncDotNet.S57.csproj @@ -38,7 +38,7 @@ Console.WriteLine($"Size: {new FileInfo(filePath).Length} bytes"); Console.WriteLine(); -using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole(options => options.IncludeScopes = true)); +using var loggerFactory = LoggerFactory.Create(builder => builder.AddSimpleConsole(options => options.IncludeScopes = true)); var logger = loggerFactory.CreateLogger("DumpChart"); // ============================================================================ @@ -59,7 +59,7 @@ ddr = Iso8211DataDescriptiveRecordReader.Read(iso8211Doc.DataDescriptiveRecord); } -for (int r = 0; r < iso8211Doc.Records.Length; r++) +for (int r = 0; r < iso8211Doc.Records.Count; r++) { var record = iso8211Doc.Records[r]; var leader = record.Leader; @@ -76,12 +76,12 @@ Console.WriteLine($"│ Base Address : {leader.BaseAddressOfFieldArea}"); Console.WriteLine($"│ Ext Char Set : {leader.ExtendedCharacterSetIndicator}"); Console.WriteLine($"│ Entry Map : tag={leader.SizeOfFieldTagField} len={leader.SizeOfFieldLengthField} pos={leader.SizeOfFieldPositionField}"); - Console.WriteLine($"│ Directory Entries : {record.Directory.Length}"); - Console.WriteLine($"│ Fields : {record.Fields.Length}"); + Console.WriteLine($"│ Directory Entries : {record.Directory.Count}"); + Console.WriteLine($"│ Fields : {record.Fields.Count}"); Console.WriteLine("│"); // Directory entries - if (record.Directory.Length > 0) + if (record.Directory.Count > 0) { Console.WriteLine("│ ┌─ Directory ────────────────────────────────────────"); foreach (var entry in record.Directory) @@ -93,7 +93,7 @@ } // Fields with hex dump - for (int f = 0; f < record.Fields.Length; f++) + for (int f = 0; f < record.Fields.Count; f++) { var field = record.Fields[f]; Console.WriteLine($"│ ┌─ Field {f}: Tag = \"{field.Tag}\" ({field.Data.Length} bytes) ──────"); @@ -138,7 +138,7 @@ Console.WriteLine($"│ Format Controls: {fieldDef.FormatControls}"); Console.WriteLine($"│ Repeating Group: {(fieldDef.HasRepeatingGroup ? $"Yes (from index {fieldDef.RepeatingSubfieldStartIndex})" : "No")}"); - if (!fieldDef.SubfieldDefinitions.IsDefaultOrEmpty) + if (fieldDef.SubfieldDefinitions.Count > 0) { Console.WriteLine("│ Subfields:"); foreach (var sf in fieldDef.SubfieldDefinitions) @@ -197,10 +197,10 @@ } // --- Feature Records --- -Console.WriteLine($"┌─── Feature Records ({s57Doc.FeatureRecords.Length} total) ─────────────────────────"); +Console.WriteLine($"┌─── Feature Records ({s57Doc.FeatureRecords.Count} total) ─────────────────────────"); Console.WriteLine("│"); -for (int i = 0; i < s57Doc.FeatureRecords.Length; i++) +for (int i = 0; i < s57Doc.FeatureRecords.Count; i++) { var feature = s57Doc.FeatureRecords[i]; @@ -213,7 +213,7 @@ Console.WriteLine($"│ │ Update Instr : {feature.UpdateInstruction}"); // Attributes - if (!feature.Attributes.IsDefaultOrEmpty && feature.Attributes.Length > 0) + if (feature.Attributes.Count > 0) { Console.WriteLine("│ │ Attributes (ATTF):"); foreach (var attr in feature.Attributes) @@ -223,7 +223,7 @@ } // National Attributes - if (!feature.NationalAttributes.IsDefaultOrEmpty && feature.NationalAttributes.Length > 0) + if (feature.NationalAttributes.Count > 0) { Console.WriteLine("│ │ National Attributes (NATF):"); foreach (var attr in feature.NationalAttributes) @@ -233,7 +233,7 @@ } // Spatial Pointers - if (!feature.SpatialPointers.IsDefaultOrEmpty && feature.SpatialPointers.Length > 0) + if (feature.SpatialPointers.Count > 0) { Console.WriteLine("│ │ Spatial Pointers (FSPT):"); foreach (var sp in feature.SpatialPointers) @@ -243,7 +243,7 @@ } // Feature Pointers - if (!feature.FeaturePointers.IsDefaultOrEmpty && feature.FeaturePointers.Length > 0) + if (feature.FeaturePointers.Count > 0) { Console.WriteLine("│ │ Feature Pointers (FFPT):"); foreach (var fp in feature.FeaturePointers) @@ -262,10 +262,10 @@ int comf = s57Doc.CoordinateMultiplicationFactor; int somf = s57Doc.SoundingMultiplicationFactor; -Console.WriteLine($"┌─── Vector Records ({s57Doc.VectorRecords.Length} total) ──────────────────────────"); +Console.WriteLine($"┌─── Vector Records ({s57Doc.VectorRecords.Count} total) ──────────────────────────"); Console.WriteLine("│"); -for (int i = 0; i < s57Doc.VectorRecords.Length; i++) +for (int i = 0; i < s57Doc.VectorRecords.Count; i++) { var vector = s57Doc.VectorRecords[i]; @@ -284,7 +284,7 @@ Console.WriteLine($"│ │ Update Instr : {vector.UpdateInstruction}"); // Attributes - if (!vector.Attributes.IsDefaultOrEmpty && vector.Attributes.Length > 0) + if (vector.Attributes.Count > 0) { Console.WriteLine("│ │ Attributes (ATTV):"); foreach (var attr in vector.Attributes) @@ -294,7 +294,7 @@ } // Vector Pointers - if (!vector.VectorPointers.IsDefaultOrEmpty && vector.VectorPointers.Length > 0) + if (vector.VectorPointers.Count > 0) { Console.WriteLine("│ │ Vector Pointers (VRPT):"); foreach (var vp in vector.VectorPointers) @@ -304,36 +304,36 @@ } // 2D Coordinates - if (!vector.Coordinates2D.IsDefaultOrEmpty && vector.Coordinates2D.Length > 0) + if (vector.Coordinates2D.Count > 0) { - Console.WriteLine($"│ │ 2D Coordinates (SG2D): {vector.Coordinates2D.Length} point(s)"); - int maxCoords = Math.Min(vector.Coordinates2D.Length, 20); + Console.WriteLine($"│ │ 2D Coordinates (SG2D): {vector.Coordinates2D.Count} point(s)"); + int maxCoords = Math.Min(vector.Coordinates2D.Count, 20); for (int c = 0; c < maxCoords; c++) { var coord = vector.Coordinates2D[c]; var (lon, lat) = coord.ToDecimalDegrees(comf); Console.WriteLine($"│ │ [{c,4}] Y={coord.Y,12} X={coord.X,12} ({lat:F7}°, {lon:F7}°)"); } - if (vector.Coordinates2D.Length > maxCoords) + if (vector.Coordinates2D.Count > maxCoords) { - Console.WriteLine($"│ │ ... and {vector.Coordinates2D.Length - maxCoords} more point(s)"); + Console.WriteLine($"│ │ ... and {vector.Coordinates2D.Count - maxCoords} more point(s)"); } } // 3D Soundings - if (!vector.Soundings.IsDefaultOrEmpty && vector.Soundings.Length > 0) + if (vector.Soundings.Count > 0) { - Console.WriteLine($"│ │ 3D Soundings (SG3D): {vector.Soundings.Length} sounding(s)"); - int maxSoundings = Math.Min(vector.Soundings.Length, 20); + Console.WriteLine($"│ │ 3D Soundings (SG3D): {vector.Soundings.Count} sounding(s)"); + int maxSoundings = Math.Min(vector.Soundings.Count, 20); for (int s = 0; s < maxSoundings; s++) { var snd = vector.Soundings[s]; var (lon, lat, depth) = snd.ToDecimalValues(comf, somf); Console.WriteLine($"│ │ [{s,4}] Y={snd.Y,12} X={snd.X,12} D={snd.Depth,8} ({lat:F7}°, {lon:F7}°, {depth:F1}m)"); } - if (vector.Soundings.Length > maxSoundings) + if (vector.Soundings.Count > maxSoundings) { - Console.WriteLine($"│ │ ... and {vector.Soundings.Length - maxSoundings} more sounding(s)"); + Console.WriteLine($"│ │ ... and {vector.Soundings.Count - maxSoundings} more sounding(s)"); } } @@ -347,10 +347,10 @@ Console.WriteLine("╔══════════════════════════════════════════════════════════════════════╗"); Console.WriteLine("║ SUMMARY ║"); Console.WriteLine("╚══════════════════════════════════════════════════════════════════════╝"); -Console.WriteLine($" ISO 8211 Records : {iso8211Doc.Records.Length}"); -Console.WriteLine($" DDR Fields : {(ddr is not null ? ddr.FieldDefinitions.Length : 0)}"); -Console.WriteLine($" Feature Records : {s57Doc.FeatureRecords.Length}"); -Console.WriteLine($" Vector Records : {s57Doc.VectorRecords.Length}"); +Console.WriteLine($" ISO 8211 Records : {iso8211Doc.Records.Count}"); +Console.WriteLine($" DDR Fields : {(ddr is not null ? ddr.FieldDefinitions.Count : 0)}"); +Console.WriteLine($" Feature Records : {s57Doc.FeatureRecords.Count}"); +Console.WriteLine($" Vector Records : {s57Doc.VectorRecords.Count}"); Console.WriteLine($" Coord Mult Factor : {comf}"); Console.WriteLine($" Sound Mult Factor : {somf}"); Console.WriteLine(); diff --git a/scripts/ReadCatalog.cs b/scripts/ReadCatalog.cs index fac4c33..334fad1 100644 --- a/scripts/ReadCatalog.cs +++ b/scripts/ReadCatalog.cs @@ -43,7 +43,7 @@ try { var document = Iso8211DocumentReader.ReadFromFile(file); - totalRecords += document.Records.Length; + totalRecords += document.Records.Count; totalFiles++; } catch (Exception ex) diff --git a/scripts/ReadCatalogS57.cs b/scripts/ReadCatalogS57.cs index ba150ec..52e50dc 100755 --- a/scripts/ReadCatalogS57.cs +++ b/scripts/ReadCatalogS57.cs @@ -1,7 +1,7 @@ #!/usr/bin/env dotnet run -#:package Microsoft.Extensions.Logging@9.0.0 -#:package Microsoft.Extensions.Logging.Console@9.0.0 +#:package Microsoft.Extensions.Logging +#:package Microsoft.Extensions.Logging.Console #:project ../src/EncDotNet.S57/EncDotNet.S57.csproj @@ -39,7 +39,7 @@ Console.WriteLine(); using var loggerFactory = LoggerFactory.Create(builder => - builder.AddConsole(options => options.IncludeScopes = true)); + builder.AddSimpleConsole(options => options.IncludeScopes = true)); var logger = loggerFactory.CreateLogger("ReadCatalogS57"); int totalFeatures = 0; @@ -55,8 +55,8 @@ using var scope = logger.BeginScope("Chart: {ChartPath}", file); var document = S57DocumentReader.ReadFromFile(file, logger); var chart = S57Chart.FromDocument(document); - totalFeatures += document.FeatureRecords.Length; - totalVectors += document.VectorRecords.Length; + totalFeatures += document.FeatureRecords.Count; + totalVectors += document.VectorRecords.Count; totalFiles++; } catch (Exception ex) @@ -79,16 +79,16 @@ { Console.WriteLine("=== ISO 8211 Diagnostic Info ==="); var iso8211Doc = Iso8211DocumentReader.ReadFromFile(file); - Console.WriteLine($"Total ISO 8211 records: {iso8211Doc.Records.Length}"); + Console.WriteLine($"Total ISO 8211 records: {iso8211Doc.Records.Count}"); - if (iso8211Doc.Records.Length > 0) + if (iso8211Doc.Records.Count > 0) { Console.WriteLine(); Console.WriteLine("First few records:"); - for (int i = 0; i < Math.Min(5, iso8211Doc.Records.Length); i++) + for (int i = 0; i < Math.Min(5, iso8211Doc.Records.Count); i++) { var record = iso8211Doc.Records[i]; - Console.WriteLine($" Record {i}: {record.Fields.Length} fields"); + Console.WriteLine($" Record {i}: {record.Fields.Count} fields"); foreach (var field in record.Fields) { Console.WriteLine($" Field: {field.Tag}, Data length: {field.Data.Length} bytes");