diff --git a/src/System.Windows.Forms.Design/src/PublicAPI.Shipped.txt b/src/System.Windows.Forms.Design/src/PublicAPI.Shipped.txt
index b9ea11b684a..684b9293a03 100644
--- a/src/System.Windows.Forms.Design/src/PublicAPI.Shipped.txt
+++ b/src/System.Windows.Forms.Design/src/PublicAPI.Shipped.txt
@@ -1,7 +1,7 @@
#nullable enable
-~override System.ComponentModel.Design.ArrayEditor.CreateCollectionItemType() -> System.Type
-~override System.ComponentModel.Design.ArrayEditor.GetItems(object editValue) -> object[]
-~override System.ComponentModel.Design.ArrayEditor.SetItems(object editValue, object[] value) -> object
+override System.ComponentModel.Design.ArrayEditor.CreateCollectionItemType() -> System.Type!
+override System.ComponentModel.Design.ArrayEditor.GetItems(object? editValue) -> object![]!
+override System.ComponentModel.Design.ArrayEditor.SetItems(object? editValue, object![]? value) -> object?
~override System.Windows.Forms.Design.ComponentTray.GetService(System.Type serviceType) -> object
~override System.Windows.Forms.Design.ComponentTray.OnDragDrop(System.Windows.Forms.DragEventArgs de) -> void
~override System.Windows.Forms.Design.ComponentTray.OnDragEnter(System.Windows.Forms.DragEventArgs de) -> void
@@ -31,7 +31,7 @@
~override System.Windows.Forms.Design.ParentControlDesigner.SnapLines.get -> System.Collections.IList
~override System.Windows.Forms.Design.WindowsFormsDesignerOptionService.PopulateOptionCollection(System.ComponentModel.Design.DesignerOptionService.DesignerOptionCollection options) -> void
~static System.Windows.Forms.Design.ParentControlDesigner.InvokeCreateTool(System.Windows.Forms.Design.ParentControlDesigner toInvoke, System.Drawing.Design.ToolboxItem tool) -> void
-~System.ComponentModel.Design.ArrayEditor.ArrayEditor(System.Type type) -> void
+System.ComponentModel.Design.ArrayEditor.ArrayEditor(System.Type! type) -> void
~System.ComponentModel.Design.DesignerActionMethodItem.DesignerActionMethodItem(System.ComponentModel.Design.DesignerActionList actionList, string memberName, string displayName) -> void
~System.ComponentModel.Design.DesignerActionMethodItem.DesignerActionMethodItem(System.ComponentModel.Design.DesignerActionList actionList, string memberName, string displayName, bool includeAsDesignerVerb) -> void
~System.ComponentModel.Design.DesignerActionMethodItem.DesignerActionMethodItem(System.ComponentModel.Design.DesignerActionList actionList, string memberName, string displayName, string category) -> void
diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ArrayEditor.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ArrayEditor.cs
index 7ee3ed5dda0..5a1e15bc091 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ArrayEditor.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ArrayEditor.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-#nullable disable
-
namespace System.ComponentModel.Design;
///
@@ -22,12 +20,16 @@ public ArrayEditor(Type type) : base(type)
/// Gets or sets the data type this collection contains.
///
protected override Type CreateCollectionItemType()
- => CollectionType?.GetElementType();
+ {
+ Type? type = CollectionType.GetElementType();
+
+ return type is null ? throw new InvalidOperationException() : type;
+ }
///
/// Gets the items in the array.
///
- protected override object[] GetItems(object editValue)
+ protected override object[] GetItems(object? editValue)
{
if (editValue is Array valueArray)
{
@@ -42,7 +44,7 @@ protected override object[] GetItems(object editValue)
///
/// Sets the items in the array.
///
- protected override object SetItems(object editValue, object[] value)
+ protected override object? SetItems(object? editValue, object[]? value)
{
if (editValue is not null and not Array)
{
diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/CollectionEditor.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/CollectionEditor.cs
index d6579661143..807bd5244c0 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/CollectionEditor.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/CollectionEditor.cs
@@ -23,7 +23,7 @@ public partial class CollectionEditor : UITypeEditor
///
/// Initializes a new instance of the class using the specified collection type.
///
- public CollectionEditor(Type type) => CollectionType = type;
+ public CollectionEditor(Type type) => CollectionType = type.OrThrowIfNull();
///
/// Gets the data type of each item in the collection.
diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ArrayEditorTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ArrayEditorTests.cs
index bda27a91e4d..a7e75178e24 100644
--- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ArrayEditorTests.cs
+++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ArrayEditorTests.cs
@@ -11,17 +11,8 @@ namespace System.ComponentModel.Design.Tests;
public class ArrayEditorTests
{
[Theory]
- [InlineData(typeof(object), null)]
- [InlineData(typeof(string), null)]
+ [InlineData(typeof(string[]), typeof(string))]
[InlineData(typeof(int[]), typeof(int))]
- [InlineData(typeof(IList), null)]
- [InlineData(typeof(IList), null)]
- [InlineData(typeof(ClassWithItem), null)]
- [InlineData(typeof(ClassWithPrivateItem), null)]
- [InlineData(typeof(ClassWithStaticItem), null)]
- [InlineData(typeof(ClassWithItems), null)]
- [InlineData(typeof(ClassWithPrivateItems), null)]
- [InlineData(typeof(ClassWithStaticItems), null)]
public void ArrayEditor_Ctor_Type(Type type, Type expectedItemType)
{
SubArrayEditor editor = new(type);
@@ -34,16 +25,27 @@ public void ArrayEditor_Ctor_Type(Type type, Type expectedItemType)
Assert.Equal([expectedItemType], editor.NewItemTypes);
}
+ [Theory]
+ [InlineData(typeof(object))]
+ [InlineData(typeof(string))]
+ [InlineData(typeof(IList))]
+ [InlineData(typeof(IList))]
+ [InlineData(typeof(ClassWithItem))]
+ [InlineData(typeof(ClassWithPrivateItem))]
+ [InlineData(typeof(ClassWithStaticItem))]
+ [InlineData(typeof(ClassWithItems))]
+ [InlineData(typeof(ClassWithPrivateItems))]
+ [InlineData(typeof(ClassWithStaticItems))]
+ public void ArrayEditor_Ctor_Invalid_Type(Type type)
+ {
+ SubArrayEditor editor = new(type);
+ Assert.Throws(() => editor.CollectionItemType);
+ }
+
[Fact]
- public void ArrayEditor_Ctor_NullType()
+ public void ArrayEditor_Ctor_NullType_ThrowsArgumentNullException()
{
- SubArrayEditor editor = new(null);
- Assert.Null(editor.CollectionItemType);
- Assert.Null(editor.CollectionType);
- Assert.Null(editor.Context);
- Assert.Equal("net.ComponentModel.CollectionEditor", editor.HelpTopic);
- Assert.False(editor.IsDropDownResizable);
- Assert.Equal([null], editor.NewItemTypes);
+ Assert.Throws(() => new SubArrayEditor(null));
}
public static IEnumerable