Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class UseRegexSourceGeneratorFixer : CodeFixProvider

public override FixAllProvider? GetFixAllProvider()
{
return null;
return WellKnownFixAllProviders.BatchFixer;
}

public override async Task RegisterCodeFixesAsync(CodeFixContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1601,4 +1601,52 @@ await CreateProjectBuilder()
.ValidateAsync();
}
#endif

#if CSHARP11_OR_GREATER
[Fact]
public async Task BatchFix_MultipleRegex()
{
const string SourceCode = """
using System;
using System.Text.RegularExpressions;

class Test1
{
Regex a = [|new Regex("pattern1")|];
}

class Test2
{
Regex b = [|new Regex("pattern2")|];
}
""";

const string CodeFix = """
using System;
using System.Text.RegularExpressions;

partial class Test1
{
Regex a = MyRegex();

[GeneratedRegex("pattern1")]
private static partial Regex MyRegex();
}

partial class Test2
{
Regex b = MyRegex();

[GeneratedRegex("pattern2")]
private static partial Regex MyRegex();
}
""";

await CreateProjectBuilder()
.WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp11)
.WithSourceCode(SourceCode)
.ShouldBatchFixCodeWith(CodeFix)
.ValidateAsync();
}
#endif
}
Loading