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
Expand Up @@ -56,7 +56,7 @@ public CollectionEditorCollectionForm(CollectionEditor editor) : base(editor)
ScaleButtonImageLogicalToDevice(_upButton);
}

Text = string.Format(SR.CollectionEditorCaption, CollectionItemType.Name);
Text = string.Format(SR.CollectionEditorCaption, GetCollectionItemTypeNameForCaption(CollectionItemType));

HookEvents();

Expand All @@ -76,6 +76,20 @@ public CollectionEditorCollectionForm(CollectionEditor editor) : base(editor)
AdjustListBoxItemHeight();
}

private static string GetCollectionItemTypeNameForCaption(Type collectionItemType)
{
string itemTypeName = collectionItemType.Name;

if (collectionItemType is { IsGenericType: true, GenericTypeArguments: [Type innerType] }
&& typeof(Control).IsAssignableFrom(innerType)
&& collectionItemType.GetGenericTypeDefinition().Name.StartsWith("ControlProxy", StringComparison.Ordinal))
{
itemTypeName = innerType.Name;
}

return itemTypeName;
}

private bool IsImmutable
{
get
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
Expand Down Expand Up @@ -102,6 +102,16 @@ public void CollectionEditor_CreateCollectionForm_Invoke_Success()
Assert.NotSame(form, editor.CreateCollectionForm());
}

[Fact]
public void CollectionEditor_CreateCollectionForm_Caption_UnwrapsControlProxy()
{
SubCollectionEditor editor = new(typeof(List<ControlProxy<TestChildControl>>));
using Form form = editor.CreateCollectionForm();

Assert.Contains(nameof(TestChildControl), form.Text);
Assert.DoesNotContain("ControlProxy`1", form.Text);
}

[Theory]
[InlineData(typeof(object), typeof(object))]
[InlineData(typeof(int[]), typeof(object))]
Expand All @@ -120,6 +130,14 @@ public void CollectionEditor_CreateCollectionItemType_Invoke_ReturnsExpected(Typ
Assert.Same(itemType, editor.CreateCollectionItemType());
}

private sealed class ControlProxy<TControl>
{
}

private sealed class TestChildControl : Control
{
}

public static IEnumerable<object[]> InvalidDesignerHost_TestData()
{
yield return new object[] { null };
Expand Down