Skip to content

Commit 58fcd13

Browse files
committed
Add a project-scoped alias of File to MissingFileMethods
1 parent 9860a90 commit 58fcd13

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Tools/LeanCode.CodeAnalysis/CodeActions/FixCQRSHandlerNamespaceCodeAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ CancellationToken cancellationToken
115115
}
116116

117117
var updatedText = (await document.GetTextAsync(cancellationToken)).ToString();
118-
await MissingFileMethods.WriteAllTextAsync(newPath, updatedText, cancellationToken);
118+
await File.WriteAllTextAsync(newPath, updatedText, cancellationToken);
119119
File.Delete(document.FilePath);
120120
}
121121
}

src/Tools/LeanCode.CodeAnalysis/NetStandard21Compatibility/MissingFileMethods.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Based on https://github.com/dotnet/runtime/blob/5535e31a712343a63f5d7d796cd874e563e5ac14/src/libraries/System.Private.CoreLib/src/System/IO/File.cs
22
// as linked by docs on 02.09.2024
33

4+
global using File = LeanCode.CodeAnalysis.NetStandard21Compatibility.MissingFileMethods;
45
using System.Text;
56

6-
namespace System.IO;
7+
namespace LeanCode.CodeAnalysis.NetStandard21Compatibility;
78

89
public static class MissingFileMethods
910
{
@@ -12,6 +13,8 @@ public static class MissingFileMethods
1213
throwOnInvalidBytes: true
1314
);
1415

16+
public static void Delete(string path) => System.IO.File.Delete(path);
17+
1518
public static Task WriteAllTextAsync(
1619
string path,
1720
string? contents,
@@ -30,9 +33,11 @@ public static async Task WriteAllTextAsync(
3033
throw new ArgumentException("Path is invalid");
3134
}
3235

33-
using var stream = File.OpenWrite(path);
36+
using var stream = System.IO.File.OpenWrite(path);
37+
3438
var preamble = encoding.GetPreamble();
3539
await stream.WriteAsync(preamble, 0, preamble.Length, cancellationToken);
40+
3641
if (contents is not null)
3742
{
3843
var encoded = encoding.GetBytes(contents);

0 commit comments

Comments
 (0)