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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If have a few questions here:

  • What was/is the behavior in NetFX here? Do we also have such a converter there?
  • Is this just for the ComboBox? How does the ListBox for example handle this?

{
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 @@ -405,6 +405,7 @@ protected override Size DefaultSize
[RefreshProperties(RefreshProperties.Repaint),
AttributeProvider(typeof(IListSource))]
[SRDescription(nameof(SR.ListControlDataSourceDescr))]
[TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Windows.Forms.Design")]
public new object? DataSource
{
get => base.DataSource;
Expand Down