Skip to content

Commit 6d47f76

Browse files
authored
Use SR.Format in a few more places (#77615)
1 parent fdaaa61 commit 6d47f76

File tree

9 files changed

+34
-34
lines changed

9 files changed

+34
-34
lines changed

src/libraries/System.ComponentModel.Composition/tests/System/ComponentModel/Composition/CompositionExceptionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ private void AssertMessage(CompositionException exception, int rootCauseCount, C
416416
}
417417
else
418418
{
419-
string option1 = string.Format(CultureInfo.CurrentCulture, SR.CompositionException_SingleErrorWithMultiplePaths, rootCauseCount);
420-
string option2 = string.Format(CultureInfo.CurrentCulture, SR.CompositionException_MultipleErrorsWithMultiplePaths, rootCauseCount);
419+
string option1 = SR.Format(SR.CompositionException_SingleErrorWithMultiplePaths, rootCauseCount);
420+
string option2 = SR.Format(SR.CompositionException_MultipleErrorsWithMultiplePaths, rootCauseCount);
421421
if (!line.Contains(option1) && !line.Contains(option2))
422422
{
423423
throw new XunitException($"`{line}` contains neither `{option1}` nor `{option2}`");

src/libraries/System.ComponentModel.Composition/tests/System/ComponentModel/Composition/Hosting/TypeCatalogTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public void ICompositionElementDisplayName_SingleTypeAsTypesArgument_ShouldInclu
288288
{
289289
var catalog = (ICompositionElement)CreateTypeCatalog(e);
290290

291-
string expected = string.Format(SR.TypeCatalog_DisplayNameFormat, typeof(TypeCatalog).Name, AttributedModelServices.GetTypeIdentity(e));
291+
string expected = SR.Format(SR.TypeCatalog_DisplayNameFormat, typeof(TypeCatalog).Name, AttributedModelServices.GetTypeIdentity(e));
292292

293293
Assert.Equal(expected, catalog.DisplayName);
294294
}
@@ -334,7 +334,7 @@ public void ICompositionElementDisplayName_ShouldIncludeDerivedCatalogTypeNameAn
334334
{
335335
var catalog = (ICompositionElement)new DerivedTypeCatalog(e);
336336

337-
string expected = string.Format(SR.TypeCatalog_DisplayNameFormat, typeof(DerivedTypeCatalog).Name, AttributedModelServices.GetTypeIdentity(e));
337+
string expected = SR.Format(SR.TypeCatalog_DisplayNameFormat, typeof(DerivedTypeCatalog).Name, AttributedModelServices.GetTypeIdentity(e));
338338

339339
Assert.Equal(expected, catalog.DisplayName);
340340
}

src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/ExceptionUtilTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void ParameterInvalid()
8888
ArgumentException e = ExceptionUtil.ParameterInvalid("foo");
8989
Assert.NotNull(e);
9090
Assert.Equal("foo", e.ParamName);
91-
Assert.StartsWith(string.Format(SR.GetResourceString("Parameter_Invalid", null), "foo"), e.Message);
91+
Assert.StartsWith(SR.Format(SR.GetResourceString("Parameter_Invalid", null), "foo"), e.Message);
9292
}
9393

9494
[Fact]
@@ -97,7 +97,7 @@ public void ParameterNullOrEmpty()
9797
ArgumentException e = ExceptionUtil.ParameterNullOrEmpty("foo");
9898
Assert.NotNull(e);
9999
Assert.Equal("foo", e.ParamName);
100-
Assert.StartsWith(string.Format(SR.GetResourceString("Parameter_NullOrEmpty", null), "foo"), e.Message);
100+
Assert.StartsWith(SR.Format(SR.GetResourceString("Parameter_NullOrEmpty", null), "foo"), e.Message);
101101
}
102102

103103
[Fact]
@@ -106,7 +106,7 @@ public void PropertyInvalid()
106106
ArgumentException e = ExceptionUtil.PropertyInvalid("foo");
107107
Assert.NotNull(e);
108108
Assert.Equal("foo", e.ParamName);
109-
Assert.StartsWith(string.Format(SR.GetResourceString("Property_Invalid", null), "foo"), e.Message);
109+
Assert.StartsWith(SR.Format(SR.GetResourceString("Property_Invalid", null), "foo"), e.Message);
110110
}
111111

112112
[Fact]
@@ -115,15 +115,15 @@ public void PropertyNullOrEmpty()
115115
ArgumentException e = ExceptionUtil.PropertyNullOrEmpty("foo");
116116
Assert.NotNull(e);
117117
Assert.Equal("foo", e.ParamName);
118-
Assert.StartsWith(string.Format(SR.GetResourceString("Property_NullOrEmpty", null), "foo"), e.Message);
118+
Assert.StartsWith(SR.Format(SR.GetResourceString("Property_NullOrEmpty", null), "foo"), e.Message);
119119
}
120120

121121
[Fact]
122122
public void UnexpectedError()
123123
{
124124
InvalidOperationException e = ExceptionUtil.UnexpectedError("foo");
125125
Assert.NotNull(e);
126-
Assert.StartsWith(string.Format(SR.GetResourceString("Unexpected_Error", null), "foo"), e.Message);
126+
Assert.StartsWith(SR.Format(SR.GetResourceString("Unexpected_Error", null), "foo"), e.Message);
127127
}
128128
}
129129
}

src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/ValidatiorUtilsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void ValidateIntScalar(int value, int min, int max, int resolution, bool
5353
else
5454
{
5555
Assert.Equal(
56-
string.Format(SR.GetResourceString(message, null), min, max),
56+
SR.Format(SR.GetResourceString(message, null), min, max),
5757
AssertExtensions.Throws<ArgumentException>(null, action).Message);
5858
}
5959
}
@@ -72,7 +72,7 @@ public void ValidateIntBadResolution(int value, int min, int max, int resolution
7272
else
7373
{
7474
Assert.Equal(
75-
string.Format(SR.GetResourceString(message, null), resolution),
75+
SR.Format(SR.GetResourceString(message, null), resolution),
7676
AssertExtensions.Throws<ArgumentException>(null, action).Message);
7777
}
7878
}

src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSGeneratorFactory.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known
127127
case KnownManagedType.DateTime when jsType == JSTypeFlags.Missing:
128128
case KnownManagedType.DateTimeOffset when jsType == JSTypeFlags.Missing:
129129
case KnownManagedType.Object when jsType == JSTypeFlags.Missing:
130-
throw failWithReason(string.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
130+
throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
131131

132132
// nullable
133133
case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Boolean && jsType == JSTypeFlags.Boolean: return new NullableJSGenerator(MarshalerType.Boolean);
@@ -157,10 +157,10 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known
157157
case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int64 && jsType == JSTypeFlags.Missing:
158158
case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.DateTime && jsType == JSTypeFlags.Missing:
159159
case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.DateTimeOffset && jsType == JSTypeFlags.Missing:
160-
throw failWithReason(string.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
160+
throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
161161

162162
case KnownManagedType.Nullable:
163-
throw failWithReason(string.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
163+
throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
164164

165165
// task
166166
case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes.Length == 0 && jsTypeArguments[0] == JSTypeFlags.Void: return new TaskJSGenerator(MarshalerType.Void);
@@ -200,10 +200,10 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known
200200
case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.DateTime && jsType == JSTypeFlags.Missing:
201201
case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.DateTimeOffset && jsType == JSTypeFlags.Missing:
202202
case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Object && jsType == JSTypeFlags.Missing:
203-
throw failWithReason(string.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
203+
throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
204204

205205
case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1:
206-
throw failWithReason(string.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
206+
throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
207207

208208
// array
209209
case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Byte && jsTypeArguments[0] == JSTypeFlags.Number: return new ArrayJSGenerator(MarshalerType.Byte);
@@ -220,11 +220,11 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known
220220
case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Missing: return new ArrayJSGenerator(MarshalerType.Int32);
221221
case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.JSObject && jsType == JSTypeFlags.Missing: return new ArrayJSGenerator(MarshalerType.JSObject);
222222
case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1:
223-
throw failWithReason(string.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
223+
throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
224224

225225
// array forced
226226
case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.Object && jsType == JSTypeFlags.Missing:
227-
throw failWithReason(string.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
227+
throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
228228

229229
// span view
230230
case KnownManagedType.Span when jsType == JSTypeFlags.MemoryView && jsTypeArguments.Length != 0:
@@ -234,13 +234,13 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known
234234
case KnownManagedType.Span when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Double: return new SpanJSGenerator(MarshalerType.Double);
235235

236236
case KnownManagedType.Span when jsType == JSTypeFlags.MemoryView:
237-
throw failWithReason(string.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
237+
throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
238238

239239
// span forced
240240
case KnownManagedType.Span when argumentTypes[0] == KnownManagedType.Byte && jsType == JSTypeFlags.Missing:
241241
case KnownManagedType.Span when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Missing:
242242
case KnownManagedType.Span when argumentTypes[0] == KnownManagedType.Double && jsType == JSTypeFlags.Missing:
243-
throw failWithReason(string.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
243+
throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
244244

245245
// segment view
246246
case KnownManagedType.ArraySegment when jsType == JSTypeFlags.MemoryView && jsTypeArguments.Length != 0:
@@ -249,13 +249,13 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known
249249
case KnownManagedType.ArraySegment when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Int32: return new ArraySegmentJSGenerator(MarshalerType.Int32);
250250
case KnownManagedType.ArraySegment when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Double: return new ArraySegmentJSGenerator(MarshalerType.Double);
251251
case KnownManagedType.ArraySegment when jsType == JSTypeFlags.MemoryView:
252-
throw failWithReason(string.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
252+
throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
253253

254254
// segment forced
255255
case KnownManagedType.ArraySegment when argumentTypes[0] == KnownManagedType.Byte && jsType == JSTypeFlags.Missing:
256256
case KnownManagedType.ArraySegment when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Missing:
257257
case KnownManagedType.ArraySegment when argumentTypes[0] == KnownManagedType.Double && jsType == JSTypeFlags.Missing:
258-
throw failWithReason(string.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
258+
throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
259259

260260
// function + action
261261
case KnownManagedType.Function when jsType == JSTypeFlags.Function && jsTypeArguments.Length == argumentTypes.Length:
@@ -273,7 +273,7 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known
273273
|| argumentTypes[i] == KnownManagedType.Unknown
274274
)
275275
{
276-
throw failWithReason(string.Format(SR.FuncArgumentNotSupported, argumentTypes[i]));
276+
throw failWithReason(SR.Format(SR.FuncArgumentNotSupported, argumentTypes[i]));
277277
}
278278
var gen = Create(info, isToJs ^ (!isReturn), argumentTypes[i], Array.Empty<KnownManagedType>(), jsTypeArguments[i], Array.Empty<JSTypeFlags>(), failWithReason);
279279
argsMarshalers.Add(gen.Type);
@@ -297,13 +297,13 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known
297297
|| argumentTypes[i] == KnownManagedType.Unknown
298298
)
299299
{
300-
throw failWithReason(string.Format(SR.FuncArgumentNotSupported, argumentTypes[i]));
300+
throw failWithReason(SR.Format(SR.FuncArgumentNotSupported, argumentTypes[i]));
301301
}
302302
}
303-
throw failWithReason(string.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
303+
throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
304304

305305
default:
306-
throw failWithReason(string.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
306+
throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
307307
}
308308
}
309309
}

src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportFixer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public CodeAction CreateConvertToLibraryImportCodeFix(Document document, MethodD
119119
public CodeAction CreateConvertToLibraryImportWithSuffixCodeFix(Document document, MethodDeclarationSyntax methodSyntax, char suffix, bool mayRequireAdditionalWork)
120120
{
121121
return CodeAction.Create(
122-
string.Format(SR.ConvertToLibraryImportWithSuffix, suffix),
122+
SR.Format(SR.ConvertToLibraryImportWithSuffix, suffix),
123123
cancelToken => ConvertToLibraryImport(
124124
document,
125125
methodSyntax,
@@ -155,7 +155,7 @@ await editor.GetDocumentEditorAsync(document.Id, cancelToken).ConfigureAwait(fal
155155
public CodeAction CreateConvertToLibraryImportWithSuffixCodeFix(Document document, MethodDeclarationSyntax methodSyntax, char suffix, bool mayRequireAdditionalWork)
156156
{
157157
return CodeAction.Create(
158-
string.Format(SR.ConvertToLibraryImportWithSuffixAddUnsafe, suffix),
158+
SR.Format(SR.ConvertToLibraryImportWithSuffixAddUnsafe, suffix),
159159
async cancelToken =>
160160
{
161161
Solution solutionWithUnsafe = AddUnsafe(document.Project.Solution, document.Project);

src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ private void ValidateCustomNativeTypeMarshallingSupported(TypePositionInfo info,
379379
{
380380
throw new MarshallingNotSupportedException(info, context)
381381
{
382-
NotSupportedDetails = string.Format(SR.UnmanagedToManagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
382+
NotSupportedDetails = SR.Format(SR.UnmanagedToManagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
383383
};
384384
}
385385

@@ -388,7 +388,7 @@ private void ValidateCustomNativeTypeMarshallingSupported(TypePositionInfo info,
388388
{
389389
throw new MarshallingNotSupportedException(info, context)
390390
{
391-
NotSupportedDetails = string.Format(SR.BidirectionalMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
391+
NotSupportedDetails = SR.Format(SR.BidirectionalMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
392392
};
393393
}
394394

@@ -398,7 +398,7 @@ private void ValidateCustomNativeTypeMarshallingSupported(TypePositionInfo info,
398398
{
399399
throw new MarshallingNotSupportedException(info, context)
400400
{
401-
NotSupportedDetails = string.Format(SR.ManagedToUnmanagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
401+
NotSupportedDetails = SR.Format(SR.ManagedToUnmanagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
402402
};
403403
}
404404

@@ -410,7 +410,7 @@ private void ValidateCustomNativeTypeMarshallingSupported(TypePositionInfo info,
410410
{
411411
throw new MarshallingNotSupportedException(info, context)
412412
{
413-
NotSupportedDetails = string.Format(SR.ManagedToUnmanagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
413+
NotSupportedDetails = SR.Format(SR.ManagedToUnmanagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
414414
};
415415
}
416416
}

src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshallingGeneratorFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private IMarshallingGenerator CreateCharMarshaller(TypePositionInfo info, StubCo
6464
case CharEncoding.Utf8:
6565
throw new MarshallingNotSupportedException(info, context) // [Compat] UTF-8 is not supported for char
6666
{
67-
NotSupportedDetails = string.Format(SR.MarshallingCharAsSpecifiedStringMarshallingNotSupported, nameof(CharEncoding.Utf8))
67+
NotSupportedDetails = SR.Format(SR.MarshallingCharAsSpecifiedStringMarshallingNotSupported, nameof(CharEncoding.Utf8))
6868
};
6969
case CharEncoding.Custom:
7070
throw new MarshallingNotSupportedException(info, context)

src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ private static string EscapeAscii(string path)
12181218
builder.Append(c);
12191219
break;
12201220
default:
1221-
builder.Append(string.Format($"%{((int)c):X2}"));
1221+
builder.AppendFormat("%{0:X2}", (int)c);
12221222
break;
12231223
}
12241224
}

0 commit comments

Comments
 (0)