Skip to content
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

Use SR.Format in a few more places #77615

Merged
merged 2 commits into from
Nov 2, 2022
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 @@ -416,8 +416,8 @@ private void AssertMessage(CompositionException exception, int rootCauseCount, C
}
else
{
string option1 = string.Format(CultureInfo.CurrentCulture, SR.CompositionException_SingleErrorWithMultiplePaths, rootCauseCount);
string option2 = string.Format(CultureInfo.CurrentCulture, SR.CompositionException_MultipleErrorsWithMultiplePaths, rootCauseCount);
string option1 = SR.Format(SR.CompositionException_SingleErrorWithMultiplePaths, rootCauseCount);
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
string option2 = SR.Format(SR.CompositionException_MultipleErrorsWithMultiplePaths, rootCauseCount);
if (!line.Contains(option1) && !line.Contains(option2))
{
throw new XunitException($"`{line}` contains neither `{option1}` nor `{option2}`");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public void ICompositionElementDisplayName_SingleTypeAsTypesArgument_ShouldInclu
{
var catalog = (ICompositionElement)CreateTypeCatalog(e);

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

Assert.Equal(expected, catalog.DisplayName);
}
Expand Down Expand Up @@ -334,7 +334,7 @@ public void ICompositionElementDisplayName_ShouldIncludeDerivedCatalogTypeNameAn
{
var catalog = (ICompositionElement)new DerivedTypeCatalog(e);

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

Assert.Equal(expected, catalog.DisplayName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void ParameterInvalid()
ArgumentException e = ExceptionUtil.ParameterInvalid("foo");
Assert.NotNull(e);
Assert.Equal("foo", e.ParamName);
Assert.StartsWith(string.Format(SR.GetResourceString("Parameter_Invalid", null), "foo"), e.Message);
Assert.StartsWith(SR.Format(SR.GetResourceString("Parameter_Invalid", null), "foo"), e.Message);
}

[Fact]
Expand All @@ -97,7 +97,7 @@ public void ParameterNullOrEmpty()
ArgumentException e = ExceptionUtil.ParameterNullOrEmpty("foo");
Assert.NotNull(e);
Assert.Equal("foo", e.ParamName);
Assert.StartsWith(string.Format(SR.GetResourceString("Parameter_NullOrEmpty", null), "foo"), e.Message);
Assert.StartsWith(SR.Format(SR.GetResourceString("Parameter_NullOrEmpty", null), "foo"), e.Message);
}

[Fact]
Expand All @@ -106,7 +106,7 @@ public void PropertyInvalid()
ArgumentException e = ExceptionUtil.PropertyInvalid("foo");
Assert.NotNull(e);
Assert.Equal("foo", e.ParamName);
Assert.StartsWith(string.Format(SR.GetResourceString("Property_Invalid", null), "foo"), e.Message);
Assert.StartsWith(SR.Format(SR.GetResourceString("Property_Invalid", null), "foo"), e.Message);
}

[Fact]
Expand All @@ -115,15 +115,15 @@ public void PropertyNullOrEmpty()
ArgumentException e = ExceptionUtil.PropertyNullOrEmpty("foo");
Assert.NotNull(e);
Assert.Equal("foo", e.ParamName);
Assert.StartsWith(string.Format(SR.GetResourceString("Property_NullOrEmpty", null), "foo"), e.Message);
Assert.StartsWith(SR.Format(SR.GetResourceString("Property_NullOrEmpty", null), "foo"), e.Message);
}

[Fact]
public void UnexpectedError()
{
InvalidOperationException e = ExceptionUtil.UnexpectedError("foo");
Assert.NotNull(e);
Assert.StartsWith(string.Format(SR.GetResourceString("Unexpected_Error", null), "foo"), e.Message);
Assert.StartsWith(SR.Format(SR.GetResourceString("Unexpected_Error", null), "foo"), e.Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void ValidateIntScalar(int value, int min, int max, int resolution, bool
else
{
Assert.Equal(
string.Format(SR.GetResourceString(message, null), min, max),
SR.Format(SR.GetResourceString(message, null), min, max),
AssertExtensions.Throws<ArgumentException>(null, action).Message);
}
}
Expand All @@ -72,7 +72,7 @@ public void ValidateIntBadResolution(int value, int min, int max, int resolution
else
{
Assert.Equal(
string.Format(SR.GetResourceString(message, null), resolution),
SR.Format(SR.GetResourceString(message, null), resolution),
AssertExtensions.Throws<ArgumentException>(null, action).Message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known
case KnownManagedType.DateTime when jsType == JSTypeFlags.Missing:
case KnownManagedType.DateTimeOffset when jsType == JSTypeFlags.Missing:
case KnownManagedType.Object when jsType == JSTypeFlags.Missing:
throw failWithReason(string.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));

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

case KnownManagedType.Nullable:
throw failWithReason(string.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));

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

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

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

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

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

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

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

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

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

// function + action
case KnownManagedType.Function when jsType == JSTypeFlags.Function && jsTypeArguments.Length == argumentTypes.Length:
Expand All @@ -273,7 +273,7 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known
|| argumentTypes[i] == KnownManagedType.Unknown
)
{
throw failWithReason(string.Format(SR.FuncArgumentNotSupported, argumentTypes[i]));
throw failWithReason(SR.Format(SR.FuncArgumentNotSupported, argumentTypes[i]));
}
var gen = Create(info, isToJs ^ (!isReturn), argumentTypes[i], Array.Empty<KnownManagedType>(), jsTypeArguments[i], Array.Empty<JSTypeFlags>(), failWithReason);
argsMarshalers.Add(gen.Type);
Expand All @@ -297,13 +297,13 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known
|| argumentTypes[i] == KnownManagedType.Unknown
)
{
throw failWithReason(string.Format(SR.FuncArgumentNotSupported, argumentTypes[i]));
throw failWithReason(SR.Format(SR.FuncArgumentNotSupported, argumentTypes[i]));
}
}
throw failWithReason(string.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));
throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName));

default:
throw failWithReason(string.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public CodeAction CreateConvertToLibraryImportCodeFix(Document document, MethodD
public CodeAction CreateConvertToLibraryImportWithSuffixCodeFix(Document document, MethodDeclarationSyntax methodSyntax, char suffix, bool mayRequireAdditionalWork)
{
return CodeAction.Create(
string.Format(SR.ConvertToLibraryImportWithSuffix, suffix),
SR.Format(SR.ConvertToLibraryImportWithSuffix, suffix),
cancelToken => ConvertToLibraryImport(
document,
methodSyntax,
Expand Down Expand Up @@ -155,7 +155,7 @@ await editor.GetDocumentEditorAsync(document.Id, cancelToken).ConfigureAwait(fal
public CodeAction CreateConvertToLibraryImportWithSuffixCodeFix(Document document, MethodDeclarationSyntax methodSyntax, char suffix, bool mayRequireAdditionalWork)
{
return CodeAction.Create(
string.Format(SR.ConvertToLibraryImportWithSuffixAddUnsafe, suffix),
SR.Format(SR.ConvertToLibraryImportWithSuffixAddUnsafe, suffix),
async cancelToken =>
{
Solution solutionWithUnsafe = AddUnsafe(document.Project.Solution, document.Project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private void ValidateCustomNativeTypeMarshallingSupported(TypePositionInfo info,
{
throw new MarshallingNotSupportedException(info, context)
{
NotSupportedDetails = string.Format(SR.UnmanagedToManagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
NotSupportedDetails = SR.Format(SR.UnmanagedToManagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
};
}

Expand All @@ -388,7 +388,7 @@ private void ValidateCustomNativeTypeMarshallingSupported(TypePositionInfo info,
{
throw new MarshallingNotSupportedException(info, context)
{
NotSupportedDetails = string.Format(SR.BidirectionalMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
NotSupportedDetails = SR.Format(SR.BidirectionalMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
};
}

Expand All @@ -398,7 +398,7 @@ private void ValidateCustomNativeTypeMarshallingSupported(TypePositionInfo info,
{
throw new MarshallingNotSupportedException(info, context)
{
NotSupportedDetails = string.Format(SR.ManagedToUnmanagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
NotSupportedDetails = SR.Format(SR.ManagedToUnmanagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
};
}

Expand All @@ -410,7 +410,7 @@ private void ValidateCustomNativeTypeMarshallingSupported(TypePositionInfo info,
{
throw new MarshallingNotSupportedException(info, context)
{
NotSupportedDetails = string.Format(SR.ManagedToUnmanagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
NotSupportedDetails = SR.Format(SR.ManagedToUnmanagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private IMarshallingGenerator CreateCharMarshaller(TypePositionInfo info, StubCo
case CharEncoding.Utf8:
throw new MarshallingNotSupportedException(info, context) // [Compat] UTF-8 is not supported for char
{
NotSupportedDetails = string.Format(SR.MarshallingCharAsSpecifiedStringMarshallingNotSupported, nameof(CharEncoding.Utf8))
NotSupportedDetails = SR.Format(SR.MarshallingCharAsSpecifiedStringMarshallingNotSupported, nameof(CharEncoding.Utf8))
};
case CharEncoding.Custom:
throw new MarshallingNotSupportedException(info, context)
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ private static string EscapeAscii(string path)
builder.Append(c);
break;
default:
builder.Append(string.Format($"%{((int)c):X2}"));
builder.AppendFormat("%{0:X2}", (int)c);
break;
}
}
Expand Down