未验证 提交 6d47f766 编写于 作者: A Adeel Mujahid 提交者: GitHub

Use SR.Format in a few more places (#77615)

上级 fdaaa61d
......@@ -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);
string option2 = SR.Format(SR.CompositionException_MultipleErrorsWithMultiplePaths, rootCauseCount);
if (!line.Contains(option1) && !line.Contains(option2))
{
throw new XunitException($"`{line}` contains neither `{option1}` nor `{option2}`");
......
......@@ -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);
}
......@@ -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);
}
......
......@@ -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]
......@@ -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]
......@@ -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]
......@@ -115,7 +115,7 @@ 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]
......@@ -123,7 +123,7 @@ 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);
}
}
}
......@@ -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);
}
}
......@@ -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);
}
}
......
......@@ -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);
......@@ -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);
......@@ -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);
......@@ -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:
......@@ -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:
......@@ -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:
......@@ -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);
......@@ -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));
}
}
}
......
......@@ -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,
......@@ -155,7 +155,7 @@ public CodeAction CreateConvertToLibraryImportCodeFix(Document document, MethodD
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);
......
......@@ -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)
};
}
......@@ -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)
};
}
......@@ -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)
};
}
......@@ -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)
};
}
}
......
......@@ -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)
......
......@@ -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;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册