Skip to content

Commit f31094a

Browse files
fix: address refactor review feedback
1 parent 69a3ebc commit f31094a

22 files changed

Lines changed: 92 additions & 93 deletions

.codex/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"hooks": [
66
{
77
"type": "command",
8-
"command": "\"${CLAUDE_PROJECT_DIR:-.}\"/.claude/hooks/stop-file-length.sh",
8+
"command": "\"${CLAUDE_PROJECT_DIR:-.}\"/.codex/hooks/stop-file-length.sh",
99
"timeout": 15,
1010
"statusMessage": "Checking file lengths (400-line limit)..."
1111
}

benchmarks/CsvBenchmarks/Program.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ public void Setup()
7575
_quotedCsvPath = Path.Combine(dataDir, "quoted.csv");
7676
GenerateCsv(_quotedCsvPath, 100_000, 10, quoteAll: true);
7777

78-
Console.WriteLine($"Small CSV: {new FileInfo(_smallCsvPath).Length / 1024.0:N0} KB");
79-
Console.WriteLine($"Medium CSV: {new FileInfo(_mediumCsvPath).Length / 1024.0:N0} KB");
80-
Console.WriteLine($"Large CSV: {new FileInfo(_largeCsvPath).Length / 1024.0 / 1024.0:N1} MB");
81-
Console.WriteLine($"Wide CSV: {new FileInfo(_wideCsvPath).Length / 1024.0:N0} KB");
82-
Console.WriteLine($"Quoted CSV: {new FileInfo(_quotedCsvPath).Length / 1024.0:N0} KB");
78+
Console.WriteLine(String.Format("Small CSV: {0:N0} KB", new FileInfo(_smallCsvPath).Length / 1024.0));
79+
Console.WriteLine(String.Format("Medium CSV: {0:N0} KB", new FileInfo(_mediumCsvPath).Length / 1024.0));
80+
Console.WriteLine(String.Format("Large CSV: {0:N1} MB", new FileInfo(_largeCsvPath).Length / 1024.0 / 1024.0));
81+
Console.WriteLine(String.Format("Wide CSV: {0:N0} KB", new FileInfo(_wideCsvPath).Length / 1024.0));
82+
Console.WriteLine(String.Format("Quoted CSV: {0:N0} KB", new FileInfo(_quotedCsvPath).Length / 1024.0));
8383
}
8484

8585
private void GenerateCsv(string path, int rows, int cols, bool quoteAll)
@@ -90,7 +90,7 @@ private void GenerateCsv(string path, int rows, int cols, bool quoteAll)
9090
using var writer = new StreamWriter(path, false, Encoding.UTF8);
9191

9292
// Header
93-
writer.WriteLine(string.Join(",", Enumerable.Range(0, cols).Select(i => $"Column{i}")));
93+
writer.WriteLine(string.Join(",", Enumerable.Range(0, cols).Select(i => String.Format("Column{0}", i))));
9494

9595
var random = new Random(42);
9696
var sb = new StringBuilder();
@@ -105,16 +105,16 @@ private void GenerateCsv(string path, int rows, int cols, bool quoteAll)
105105
string value = col switch
106106
{
107107
0 => row.ToString(),
108-
1 => $"Name{row}",
108+
1 => String.Format("Name{0}", row),
109109
2 => random.Next(1, 100).ToString(),
110110
3 => random.NextDouble().ToString("F4"),
111111
4 => DateTime.Now.AddDays(-random.Next(365)).ToString("yyyy-MM-dd"),
112112
5 => random.Next(0, 2) == 0 ? "true" : "false",
113-
_ => $"Value{row}_{col}"
113+
_ => String.Format("Value{0}_{1}", row, col)
114114
};
115115

116116
if (quoteAll)
117-
sb.Append($"\"{value}\"");
117+
sb.Append(String.Format("\"{0}\"", value));
118118
else
119119
sb.Append(value);
120120
}

dbatools.library.CoreRedirector.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@
55
using System.Reflection;
66
using System.Runtime.InteropServices;
77
using System.Runtime.Loader;
8+
using System.Threading;
89

10+
// This source lives beside the module because dbatools.library.psm1 reads and compiles it at import time.
911
public class CoreRedirector
1012
{
1113
private static string _libPath;
12-
private static bool _registered = false;
14+
private static int _registered = 0;
1315
private static readonly string _platformRid = ComputePlatformRid();
1416
private static readonly string _architectureRid = ComputeArchitectureRid();
1517

1618
public static void Register(string libPath)
1719
{
18-
if (_registered) return;
20+
if (Interlocked.CompareExchange(ref _registered, 1, 0) != 0) return;
1921
_libPath = libPath;
2022
AssemblyLoadContext.Default.Resolving += OnResolving;
2123
AssemblyLoadContext.Default.ResolvingUnmanagedDll += OnResolvingUnmanagedDll;
22-
_registered = true;
2324
}
2425

2526
private static Assembly OnResolving(AssemblyLoadContext context, AssemblyName assemblyName)

project/dbatools.Tests/Csv/CsvDataReaderTest.Compression.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void TestDecompressionBombProtection_ThrowsWhenExceeded()
2020
csvBuilder.AppendLine("Name,Value");
2121
for (int i = 0; i < 100; i++)
2222
{
23-
csvBuilder.AppendLine($"Row{i},SomeDataThatRepeatsWell");
23+
csvBuilder.AppendLine(String.Format("Row{0},SomeDataThatRepeatsWell", i));
2424
}
2525
string csvData = csvBuilder.ToString();
2626
byte[] uncompressedBytes = Encoding.UTF8.GetBytes(csvData);
@@ -59,9 +59,9 @@ public void TestDecompressionBombProtection_ThrowsWhenExceeded()
5959
});
6060

6161
Assert.IsTrue(ex.Message.Contains("Decompressed data exceeded maximum allowed size"),
62-
$"Expected bomb protection message, got: {ex.Message}");
62+
String.Format("Expected bomb protection message, got: {0}", ex.Message));
6363
Assert.IsTrue(ex.Message.Contains("decompression bomb"),
64-
$"Expected 'decompression bomb' in message, got: {ex.Message}");
64+
String.Format("Expected 'decompression bomb' in message, got: {0}", ex.Message));
6565
}
6666
}
6767
}

project/dbatools.Tests/Csv/CsvDataReaderTest.ParallelProcessing.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void TestParallelProcessing_LargeFile()
5555
const int rowCount = 1000;
5656
for (int i = 0; i < rowCount; i++)
5757
{
58-
sb.AppendLine($"{i},Name{i},{i * 10},Description for row {i}");
58+
sb.AppendLine(String.Format("{0},Name{0},{1},Description for row {0}", i, i * 10));
5959
}
6060

6161
var options = new CsvReaderOptions
@@ -72,7 +72,7 @@ public void TestParallelProcessing_LargeFile()
7272
{
7373
// Verify data integrity - check that records are delivered in order
7474
Assert.AreEqual(count.ToString(), reader.GetString(0));
75-
Assert.AreEqual($"Name{count}", reader.GetString(1));
75+
Assert.AreEqual(String.Format("Name{0}", count), reader.GetString(1));
7676
Assert.AreEqual((count * 10).ToString(), reader.GetString(2));
7777
count++;
7878
}

project/dbatools.Tests/Csv/CsvDataReaderTest.RawDataAndCopy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void TestGetCurrentRawData_QuotedFields()
4141
Assert.IsTrue(reader.Read());
4242
string rawData = reader.GetCurrentRawData();
4343
// The reconstructed data should quote the field containing comma
44-
Assert.IsTrue(rawData.Contains("\"Value, with comma\""), $"Expected quoted field, got: {rawData}");
44+
Assert.IsTrue(rawData.Contains("\"Value, with comma\""), String.Format("Expected quoted field, got: {0}", rawData));
4545

4646
Assert.IsTrue(reader.Read());
4747
rawData = reader.GetCurrentRawData();

project/dbatools.Tests/Csv/CsvDataReaderTest.ThreadSafety.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void TestParallelProcessing_ConcurrentGetValueAccess()
2222
const int rowCount = 500;
2323
for (int i = 0; i < rowCount; i++)
2424
{
25-
sb.AppendLine($"{i},Name{i},{i * 10}");
25+
sb.AppendLine(String.Format("{0},Name{0},{1}", i, i * 10));
2626
}
2727

2828
var options = new CsvReaderOptions
@@ -75,7 +75,7 @@ public void TestParallelProcessing_ConcurrentGetValueAccess()
7575
}
7676

7777
Assert.AreEqual(rowCount, recordsProcessed, "Should process all records");
78-
Assert.AreEqual(0, errors.Count, $"Should have no errors, but got: {string.Join(", ", errors)}");
78+
Assert.AreEqual(0, errors.Count, String.Format("Should have no errors, but got: {0}", string.Join(", ", errors)));
7979
}
8080
}
8181

@@ -88,7 +88,7 @@ public void TestParallelProcessing_HighConcurrencyStress()
8888
const int rowCount = 1000;
8989
for (int i = 0; i < rowCount; i++)
9090
{
91-
sb.AppendLine($"{i},{i+1},{i+2},{i+3},{i+4},{i+5},{i+6},{i+7},{i+8},{i+9}");
91+
sb.AppendLine(String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", i, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8, i + 9));
9292
}
9393

9494
var options = new CsvReaderOptions
@@ -124,13 +124,13 @@ public void TestParallelProcessing_HighConcurrencyStress()
124124
}
125125

126126
Assert.AreEqual(rowCount, allValues.Count, "Should process all records");
127-
Assert.AreEqual(0, errors.Count, $"Should have no errors: {string.Join("; ", errors)}");
127+
Assert.AreEqual(0, errors.Count, String.Format("Should have no errors: {0}", string.Join("; ", errors)));
128128

129129
// Verify all record indices were captured (0 to rowCount-1)
130130
var sortedIndices = allValues.OrderBy(x => x).ToList();
131131
for (int i = 0; i < rowCount; i++)
132132
{
133-
Assert.AreEqual(i, sortedIndices[i], $"Record index {i} should be present");
133+
Assert.AreEqual(i, sortedIndices[i], String.Format("Record index {0} should be present", i));
134134
}
135135
}
136136
}
@@ -144,7 +144,7 @@ public void TestParallelProcessing_CurrentRecordIndexConsistency()
144144
const int rowCount = 200;
145145
for (int i = 0; i < rowCount; i++)
146146
{
147-
sb.AppendLine($"{i},{i * 100}");
147+
sb.AppendLine(String.Format("{0},{1}", i, i * 100));
148148
}
149149

150150
var options = new CsvReaderOptions
@@ -163,7 +163,7 @@ public void TestParallelProcessing_CurrentRecordIndexConsistency()
163163

164164
// Verify record indices are strictly increasing
165165
Assert.IsTrue(currentIndex > lastIndex,
166-
$"Record index should increase: last={lastIndex}, current={currentIndex}");
166+
String.Format("Record index should increase: last={0}, current={1}", lastIndex, currentIndex));
167167

168168
// Read the index multiple times from different threads
169169
var indices = new System.Collections.Concurrent.ConcurrentBag<long>();
@@ -175,7 +175,7 @@ public void TestParallelProcessing_CurrentRecordIndexConsistency()
175175
// All reads should return the same index (no torn reads)
176176
var uniqueIndices = indices.Distinct().ToList();
177177
Assert.AreEqual(1, uniqueIndices.Count,
178-
$"All concurrent reads should return same index, got: {string.Join(", ", uniqueIndices)}");
178+
String.Format("All concurrent reads should return same index, got: {0}", string.Join(", ", uniqueIndices)));
179179

180180
lastIndex = currentIndex;
181181
}
@@ -192,7 +192,7 @@ public void TestParallelProcessing_DisposeDuringRead()
192192
sb.AppendLine("Id,Name,Value");
193193
for (int i = 0; i < 100; i++)
194194
{
195-
sb.AppendLine($"{i},Name{i},{i * 10}");
195+
sb.AppendLine(String.Format("{0},Name{0},{1}", i, i * 10));
196196
}
197197

198198
var options = new CsvReaderOptions
@@ -234,7 +234,7 @@ public void TestParallelProcessing_DisposeDuringRead()
234234
// Should not have unexpected errors (ObjectDisposedException is fine)
235235
foreach (var error in errors)
236236
{
237-
Assert.Fail($"Unexpected error during dispose: {error}");
237+
Assert.Fail(String.Format("Unexpected error during dispose: {0}", error));
238238
}
239239
}
240240

@@ -247,7 +247,7 @@ public void TestParallelProcessing_RepeatedGetValuesStress()
247247
const int rowCount = 300;
248248
for (int i = 0; i < rowCount; i++)
249249
{
250-
sb.AppendLine($"A{i},B{i},C{i},D{i},E{i}");
250+
sb.AppendLine(String.Format("A{0},B{0},C{0},D{0},E{0}", i));
251251
}
252252

253253
var options = new CsvReaderOptions
@@ -264,7 +264,7 @@ public void TestParallelProcessing_RepeatedGetValuesStress()
264264
while (reader.Read())
265265
{
266266
recordCount++;
267-
string expectedPrefix = $"A{reader.CurrentRecordIndex}";
267+
string expectedPrefix = String.Format("A{0}", reader.CurrentRecordIndex);
268268

269269
// Multiple threads calling GetValues simultaneously
270270
System.Threading.Tasks.Parallel.For(0, 10, iteration =>
@@ -284,15 +284,15 @@ public void TestParallelProcessing_RepeatedGetValuesStress()
284284

285285
if (suffix0 != suffix1)
286286
{
287-
inconsistencies.Add($"Inconsistent record: {val0} vs {val1}");
287+
inconsistencies.Add(String.Format("Inconsistent record: {0} vs {1}", val0, val1));
288288
}
289289
}
290290
});
291291
}
292292

293293
Assert.AreEqual(rowCount, recordCount, "Should process all records");
294294
Assert.AreEqual(0, inconsistencies.Count,
295-
$"Should have consistent snapshots: {string.Join("; ", inconsistencies.Take(5))}");
295+
String.Format("Should have consistent snapshots: {0}", string.Join("; ", inconsistencies.Take(5))));
296296
}
297297
}
298298

project/dbatools.Tests/Csv/CsvSchemaInferenceTest.OptionsAndEdges.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ public void TestInferSchema_DecimalWithNoIntegerPart()
228228
var columns = CsvSchemaInference.InferSchemaFromSample(csvPath);
229229

230230
// Decimals without integer part (e.g., .5 instead of 0.5) should be handled
231-
Assert.IsTrue(columns[0].SqlDataType.Contains("decimal"), $"Expected decimal, got {columns[0].SqlDataType}");
232-
Assert.IsTrue(columns[1].SqlDataType.Contains("decimal"), $"Expected decimal, got {columns[1].SqlDataType}");
233-
Assert.IsTrue(columns[2].SqlDataType.Contains("decimal"), $"Expected decimal, got {columns[2].SqlDataType}");
231+
Assert.IsTrue(columns[0].SqlDataType.Contains("decimal"), String.Format("Expected decimal, got {0}", columns[0].SqlDataType));
232+
Assert.IsTrue(columns[1].SqlDataType.Contains("decimal"), String.Format("Expected decimal, got {0}", columns[1].SqlDataType));
233+
Assert.IsTrue(columns[2].SqlDataType.Contains("decimal"), String.Format("Expected decimal, got {0}", columns[2].SqlDataType));
234234

235235
// Verify scale is tracked correctly
236236
Assert.AreEqual(3, columns[0].Scale); // .5, .25, .125 -> max 3 digits after decimal

project/dbatools.Tests/Csv/CsvSchemaInferenceTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void TestInferSchema_RealFile_BooleanVariants()
161161

162162
foreach (var col in columns)
163163
{
164-
Assert.AreEqual("bit", col.SqlDataType, $"Column {col.ColumnName} should be bit");
164+
Assert.AreEqual("bit", col.SqlDataType, String.Format("Column {0} should be bit", col.ColumnName));
165165
}
166166
}
167167

@@ -189,7 +189,7 @@ public void TestInferSchema_RealFile_VeryLongStrings()
189189
string csvPath = Path.Combine(_tempDir, "longstrings.csv");
190190
string longString = new string('x', 5000);
191191
string veryLongString = new string('y', 10000);
192-
File.WriteAllText(csvPath, $"Short,Long,VeryLong\nabc,{longString},{veryLongString}\n");
192+
File.WriteAllText(csvPath, String.Format("Short,Long,VeryLong\nabc,{0},{1}\n", longString, veryLongString));
193193

194194
var columns = CsvSchemaInference.InferSchemaFromSample(csvPath);
195195

@@ -211,7 +211,7 @@ public void TestInferSchema_FullScan_10000Rows()
211211
{
212212
// Mix of values to test type detection
213213
string category = i % 10 == 0 ? "A" : (i % 10 == 1 ? "B" : "C");
214-
writer.WriteLine($"{i},{i * 1.5m:F2},{category}");
214+
writer.WriteLine(String.Format("{0},{1:F2},{2}", i, i * 1.5m, category));
215215
}
216216
}
217217

@@ -240,7 +240,7 @@ public void TestInferSchema_FullScan_WithCancellation()
240240
writer.WriteLine("Id,Value");
241241
for (int i = 0; i < 1000; i++)
242242
{
243-
writer.WriteLine($"{i},{i * 10}");
243+
writer.WriteLine(String.Format("{0},{1}", i, i * 10));
244244
}
245245
}
246246

@@ -268,7 +268,7 @@ public void TestInferSchema_FullScan_WithCancellation()
268268
sb.AppendLine("Id,Value");
269269
for (int i = 0; i < 10000; i++)
270270
{
271-
sb.AppendLine($"{i},{i * 10}");
271+
sb.AppendLine(String.Format("{0},{1}", i, i * 10));
272272
}
273273

274274
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())))
@@ -302,7 +302,7 @@ public void TestInferSchema_SampleVsFullScan_ConsistentResults()
302302
for (int i = 0; i < 5000; i++)
303303
{
304304
// Keep all values in same range (1-100, price ~20)
305-
writer.WriteLine($"{(i % 100) + 1},{19.99m + (i % 10) * 0.01m:F2},Product{(i % 10)}");
305+
writer.WriteLine(String.Format("{0},{1:F2},Product{2}", (i % 100) + 1, 19.99m + (i % 10) * 0.01m, i % 10));
306306
}
307307
}
308308

0 commit comments

Comments
 (0)