using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Operations;
-using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.Text;
namespace System.Text.RegularExpressions.Generator
if (!typeDeclaration.Modifiers.Any(m => m.IsKind(SyntaxKind.PartialKeyword)))
{
typesModified++;
- return typeDeclaration.AddModifiers(SyntaxFactory.Token(SyntaxKind.PartialKeyword)).WithAdditionalAnnotations(Simplifier.Annotation);
+ return typeDeclaration.AddModifiers(SyntaxFactory.Token(SyntaxKind.PartialKeyword));
}
return typeDeclaration;
Regex r = MyRegex();
}
+ [GeneratedRegex(""a|b"", RegexOptions.None)]
+ private static partial Regex MyRegex();
+}";
+
+ await VerifyCS.VerifyCodeFixAsync(test, fixedSource);
+ }
+
+ [Fact]
+ public async Task CodeFixerDoesNotSimplifyStyle()
+ {
+ string test = @"using System.Text.RegularExpressions;
+
+class Program
+{
+ static void Main()
+ {
+ int i = (4 - 4); // this shouldn't be changed by fixer
+ Regex r = [|new Regex(options: RegexOptions.None, pattern: ""a|b"")|];
+ }
+}";
+
+ string fixedSource = @"using System.Text.RegularExpressions;
+
+partial class Program
+{
+ static void Main()
+ {
+ int i = (4 - 4); // this shouldn't be changed by fixer
+ Regex r = MyRegex();
+ }
+
[GeneratedRegex(""a|b"", RegexOptions.None)]
private static partial Regex MyRegex();
}";
Regex regex = MyRegex();
}
- [GeneratedRegex(""pattern"", (RegexOptions)2048)]
+ [GeneratedRegex(""pattern"", (RegexOptions)(2048))]
private static partial Regex MyRegex();
}
";
Regex regex = MyRegex();
}
- [GeneratedRegex(""pattern"", (RegexOptions)2048)]
+ [GeneratedRegex(""pattern"", (RegexOptions)(2048))]
private static partial Regex MyRegex();
}
";