-
Notifications
You must be signed in to change notification settings - Fork 4
Retarget analysers from .NETStandard 2.1 to 2.0 #692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Patonymous
wants to merge
9
commits into
v8.1
Choose a base branch
from
analyzers-retarget
base: v8.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3561088
Change analyzer target to .NETStandard2.0
Patonymous e6ab0ba
Add functionality from .NETStandard2.1 which is missing in 2.0
Patonymous 84892ba
Update existing code to use provided substitutes
Patonymous 9ca1772
Fix writing offset
Patonymous b8f7313
Replace vendored implementations with Microsoft.Bcl.Memory
Patonymous f17893e
Fix encoding in WriteAllTextAsync
Patonymous 9d24f59
Remove unnecessary conditional compilation
Patonymous 9860a90
Remove nullability attributes
Patonymous 58fcd13
Add a project-scoped alias of File to MissingFileMethods
Patonymous File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Tools/LeanCode.CodeAnalysis/NetStandard21Compatibility/MissingFileMethods.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Based on https://github.com/dotnet/runtime/blob/5535e31a712343a63f5d7d796cd874e563e5ac14/src/libraries/System.Private.CoreLib/src/System/IO/File.cs | ||
// as linked by docs on 02.09.2024 | ||
|
||
global using File = LeanCode.CodeAnalysis.NetStandard21Compatibility.MissingFileMethods; | ||
using System.Text; | ||
|
||
namespace LeanCode.CodeAnalysis.NetStandard21Compatibility; | ||
|
||
public static class MissingFileMethods | ||
{ | ||
private static readonly Encoding UTF8NoBOM = new UTF8Encoding( | ||
encoderShouldEmitUTF8Identifier: false, | ||
throwOnInvalidBytes: true | ||
); | ||
|
||
public static void Delete(string path) => System.IO.File.Delete(path); | ||
|
||
public static Task WriteAllTextAsync( | ||
string path, | ||
string? contents, | ||
CancellationToken cancellationToken = default | ||
) => WriteAllTextAsync(path, contents, UTF8NoBOM, cancellationToken); | ||
|
||
public static async Task WriteAllTextAsync( | ||
string path, | ||
string? contents, | ||
Encoding encoding, | ||
CancellationToken cancellationToken = default | ||
) | ||
{ | ||
if (string.IsNullOrWhiteSpace(path)) | ||
{ | ||
throw new ArgumentException("Path is invalid"); | ||
} | ||
|
||
using var stream = System.IO.File.OpenWrite(path); | ||
|
||
var preamble = encoding.GetPreamble(); | ||
await stream.WriteAsync(preamble, 0, preamble.Length, cancellationToken); | ||
|
||
if (contents is not null) | ||
{ | ||
var encoded = encoding.GetBytes(contents); | ||
await stream.WriteAsync(encoded, 0, encoded.Length, cancellationToken); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Tools/LeanCode.CodeAnalysis/NetStandard21Compatibility/MissingStringMethods.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Based on https://github.com/dotnet/runtime/blob/5535e31a712343a63f5d7d796cd874e563e5ac14/src/libraries/System.Private.CoreLib/src/System/String.Searching.cs#L26C13-L26C56 | ||
// as linked by docs on 02.09.2024 | ||
|
||
namespace System; | ||
|
||
public static class MissingStringMethods | ||
{ | ||
public static bool Contains(this string s, string value, StringComparison comparisonType) => | ||
s.IndexOf(value, comparisonType) >= 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method
Contains
should handle null values for thevalue
parameter to avoid potentialArgumentNullException
.Copilot uses AI. Check for mistakes.