{
if (destinationType == typeof(string) && value is Array)
{
- return SR.Format(SR.Array, value.GetType().Name);
+ return string.Format(SR.GetResourceString(nameof(SR.Array), "{0} Array"), value.GetType().Name);
}
return base.ConvertTo(context, culture, value, destinationType);
{
if (destinationType == typeof(string) && value is ICollection)
{
- return SR.Collection;
+ return SR.GetResourceString(nameof(SR.Collection), "(Collection)");
}
return base.ConvertTo(context, culture, value, destinationType);
/// <summary>
/// Retrieves the "default" name for our culture.
/// </summary>
- private static string DefaultCultureString => SR.CultureInfoConverterDefaultCultureString;
+ private static string DefaultCultureString => SR.GetResourceString(nameof(SR.CultureInfoConverterDefaultCultureString), "(Default)");
private const string DefaultInvariantCultureString = "(Default)";
{
if (destinationType == typeof(string))
{
- return SR.CollectionConverterText;
+ return SR.GetResourceString(nameof(SR.CollectionConverterText), "(Collection)");
}
return base.ConvertTo(cxt, culture, value, destinationType);
}
string? providerName = site?.Name;
if (providerName != null && providerName.Length > 0)
{
- name = SR.Format(SR.MetaExtenderName, name, providerName);
+ name = string.Format(SR.GetResourceString(nameof(SR.MetaExtenderName), "{0} on {1}"), name, providerName);
}
}
return name;
/// </summary>
public abstract class InstanceCreationEditor
{
- public virtual string Text => SR.InstanceCreationEditorDefaultText;
+ public virtual string Text => SR.GetResourceString(nameof(SR.InstanceCreationEditorDefaultText), "(New...)");
/// <summary>
/// This method is invoked when you user chooses the link displayed by the PropertyGrid for the InstanceCreationEditor.
if (destinationType == typeof(string) && value is string)
{
- return SR.Text;
+ return SR.GetResourceString(nameof(SR.Text), "(Text)");
}
return base.ConvertTo(context, culture, value, destinationType);
/// </summary>
public class ReferenceConverter : TypeConverter
{
- private static readonly string s_none = SR.toStringNone;
+ private static readonly string s_none = SR.GetResourceString(nameof(SR.toStringNone), "(none)");
private readonly Type _type;
/// <summary>
/// </summary>
protected Exception GetConvertFromException(object? value)
{
- string? valueTypeName = value == null ? SR.Null : value.GetType().FullName;
+ string? valueTypeName = value == null ? SR.GetResourceString(nameof(SR.Null), "(null)") : value.GetType().FullName;
throw new NotSupportedException(SR.Format(SR.ConvertFromException, GetType().Name, valueTypeName));
}
/// </summary>
protected Exception GetConvertToException(object? value, Type destinationType)
{
- string? valueTypeName = value == null ? SR.Null : value.GetType().FullName;
+ string? valueTypeName = value == null ? SR.GetResourceString(nameof(SR.Null), "(null)") : value.GetType().FullName;
throw new NotSupportedException(SR.Format(SR.ConvertToException, GetType().Name, valueTypeName, destinationType.FullName));
}
{
if (value == null)
{
- return SR.none;
+ return SR.GetResourceString(nameof(SR.none), "(none)");
}
else
{
if (!_replaced)
{
_replaced = true;
- DescriptionValue = SR.Format(base.Description);
+
+ // We call string.Format here only to keep the original behavior which throws when having null description.
+ // That will keep the exception is thrown from same original place with the exact parameters.
+ DescriptionValue = string.Format(base.Description);
}
return base.Description;
}
Assert.Equal(typeof(ArgumentException), ex.GetType());
Assert.Null(ex.InnerException);
Assert.NotNull(ex.Message);
- Assert.True(ex.Message.IndexOf("'dup'") != -1);
+ Assert.True(ex.Message.IndexOf("'dup'") != -1 || ex.Message.IndexOf(" dup") != -1);
Assert.Null(ex.ParamName);
Assert.Equal(1, container.Components.Count);
Assert.Equal(typeof(ArgumentException), ex.GetType());
Assert.Null(ex.InnerException);
Assert.NotNull(ex.Message);
- Assert.True(ex.Message.IndexOf("'duP'") != -1);
+ Assert.True(ex.Message.IndexOf("'duP'") != -1 || ex.Message.IndexOf(" duP") != -1);
Assert.Null(ex.ParamName);
Assert.Equal(1, container.Components.Count);
Assert.Equal(typeof(ArgumentException), ex.GetType());
Assert.Null(ex.InnerException);
Assert.NotNull(ex.Message);
- Assert.True(ex.Message.IndexOf("'dup'") != -1);
+ Assert.True(ex.Message.IndexOf("'dup'") != -1 || ex.Message.IndexOf(" dup") != -1);
Assert.Null(ex.ParamName);
Assert.Equal(2, container.Components.Count);
Assert.Equal(1, container2.Components.Count);
Assert.Equal(typeof(ArgumentException), ex.GetType());
Assert.Null(ex.InnerException);
Assert.NotNull(ex.Message);
- Assert.True(ex.Message.IndexOf("'dup'") != -1);
+ Assert.True(ex.Message.IndexOf("'dup'") != -1 || ex.Message.IndexOf(" dup") != -1);
Assert.Null(ex.ParamName);
Assert.Equal(2, _container.Components.Count);
_container.InvokeValidateName(compB, "whatever");
Assert.Equal(typeof(ArgumentException), ex.GetType());
Assert.Null(ex.InnerException);
Assert.NotNull(ex.Message);
- Assert.True(ex.Message.IndexOf("'dup'") != -1);
+ Assert.True(ex.Message.IndexOf("'dup'") != -1 || ex.Message.IndexOf(" dup") != -1);
Assert.Null(ex.ParamName);
Assert.Equal(2, _container.Components.Count);
_container.InvokeValidateName(compC, "whatever");
Assert.Equal(typeof(ArgumentException), ex.GetType());
Assert.Null(ex.InnerException);
Assert.NotNull(ex.Message);
- Assert.True(ex.Message.IndexOf("'dup'") != -1);
+ Assert.True(ex.Message.IndexOf("'dup'") != -1 || ex.Message.IndexOf(" dup") != -1);
Assert.Null(ex.ParamName);
Assert.Equal(2, _container.Components.Count);
_container.InvokeValidateName(compD, "whatever");
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using Microsoft.DotNet.RemoteExecutor;
using System.Collections.Generic;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Linq;
using System.Reflection;
+using System.Tests;
using Xunit;
namespace System.ComponentModel.Tests
Assert.Equal("Fixed", converter.ConvertTo(new CultureInfo("en-US"), typeof(string)));
}
+ [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
+ [InlineData(false)]
+ [InlineData(true)]
+ public void CultureInfoConverterForDefaultValue(bool useSystemResourceKeys)
+ {
+ RemoteInvokeOptions options = new RemoteInvokeOptions();
+ options.RuntimeConfigurationOptions.Add("System.Resources.UseSystemResourceKeys", useSystemResourceKeys);
+
+ RemoteExecutor.Invoke(() =>
+ {
+ using (new ThreadCultureChange(null, CultureInfo.InvariantCulture))
+ {
+ Assert.Equal("", ((CultureInfo)TypeDescriptor.GetConverter(typeof(System.Globalization.CultureInfo)).ConvertFrom(null, null, "(Default)")).Name);
+ }
+ }, options).Dispose();
+ }
+
private class SubCultureInfoConverter : CultureInfoConverter
{
public new string GetCultureName(CultureInfo culture)