Skip to content
Open
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
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
using System.Globalization;

namespace System.Windows.Forms.Design;

internal class DataSourceConverter : ReferenceConverter
{
public DataSourceConverter() : base(typeof(IListSource))
{
}

public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
{
if (destinationType == typeof(string) && value is null)
{
return SR.None_lc.ToString();
}

return base.ConvertTo(context, culture, value, destinationType);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Windows.Forms.Design.Tests;

public class DataSourceConverterTests
{
private readonly DataSourceConverter _converter = new();

[Fact]
public void ConvertTo_NullValueToString_ReturnsNoneLowercase() =>
(_converter.ConvertTo(context: null, culture: null, value: null, destinationType: typeof(string)) as string).Should().Be("(none)");

[Fact]
public void ConvertTo_NonNullValueToString_CallsBase() =>
_converter.ConvertTo(context: null, culture: null, value: new(), destinationType: typeof(string)).Should().NotBe("(none)");

[Fact]
public void ConvertTo_NullValueToNonString_ThrowsNotSupportedException()
{
Action act = () => _converter.ConvertTo(context: null, culture: null, value: null, destinationType: typeof(int));

act.Should().Throw<NotSupportedException>();
}

[Theory]
[InlineData("en-US")]
[InlineData("fr-FR")]
[InlineData("de-DE")]
public void ConvertTo_NullValueWithDifferentCultures_ReturnsNoneLowercase(string cultureName) =>
(_converter.ConvertTo(context: null, culture: new(cultureName), value: null, destinationType: typeof(string)) as string).Should().Be("(none)");
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public abstract class ListControl : Control
[RefreshProperties(RefreshProperties.Repaint)]
[AttributeProvider(typeof(IListSource))]
[SRDescription(nameof(SR.ListControlDataSourceDescr))]
[TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Windows.Forms.Design")]
public object? DataSource
{
get => _dataSource;
Expand Down