@@ -134,6 +134,12 @@ internal static async Task<Regex> SourceGenRegexAsync(
134
134
return results [ 0 ] ;
135
135
}
136
136
137
+ private static readonly CultureInfo s_cultureWithMinusNegativeSign = new CultureInfo ( "" )
138
+ {
139
+ // To validate that generation still succeeds even when something other than '-' is used.
140
+ NumberFormat = new NumberFormatInfo ( ) { NegativeSign = $ "{ ( char ) 0x2212 } " }
141
+ } ;
142
+
137
143
internal static async Task < Regex [ ] > SourceGenRegexAsync (
138
144
( string pattern , CultureInfo ? culture , RegexOptions ? options , TimeSpan ? matchTimeout ) [ ] regexes , CancellationToken cancellationToken = default )
139
145
{
@@ -214,13 +220,24 @@ internal static async Task<Regex[]> SourceGenRegexAsync(
214
220
comp = comp . ReplaceSyntaxTree ( comp . SyntaxTrees . First ( ) , CSharpSyntaxTree . ParseText ( SourceText . From ( code . ToString ( ) , Encoding . UTF8 ) , s_previewParseOptions ) ) ;
215
221
216
222
// Run the generator
217
- GeneratorDriverRunResult generatorResults = s_generatorDriver . RunGenerators ( comp ! , cancellationToken ) . GetRunResult ( ) ;
218
- ImmutableArray < Diagnostic > generatorDiagnostics = generatorResults . Diagnostics . RemoveAll ( d => d . Severity <= DiagnosticSeverity . Hidden ) ;
219
- if ( generatorDiagnostics . Length != 0 )
223
+ CultureInfo origCulture = CultureInfo . CurrentCulture ;
224
+ CultureInfo . CurrentCulture = s_cultureWithMinusNegativeSign ;
225
+ GeneratorDriverRunResult generatorResults ;
226
+ ImmutableArray < Diagnostic > generatorDiagnostics ;
227
+ try
220
228
{
221
- throw new ArgumentException (
222
- string . Join ( Environment . NewLine , generatorResults . GeneratedTrees . Select ( t => NumberLines ( t . ToString ( ) ) ) ) + Environment . NewLine +
223
- string . Join ( Environment . NewLine , generatorDiagnostics ) ) ;
229
+ generatorResults = s_generatorDriver . RunGenerators ( comp ! , cancellationToken ) . GetRunResult ( ) ;
230
+ generatorDiagnostics = generatorResults . Diagnostics . RemoveAll ( d => d . Severity <= DiagnosticSeverity . Hidden ) ;
231
+ if ( generatorDiagnostics . Length != 0 )
232
+ {
233
+ throw new ArgumentException (
234
+ string . Join ( Environment . NewLine , generatorResults . GeneratedTrees . Select ( t => NumberLines ( t . ToString ( ) ) ) ) + Environment . NewLine +
235
+ string . Join ( Environment . NewLine , generatorDiagnostics ) ) ;
236
+ }
237
+ }
238
+ finally
239
+ {
240
+ CultureInfo . CurrentCulture = origCulture ;
224
241
}
225
242
226
243
// Compile the assembly to a stream
0 commit comments