Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable nullability in TabPageCollectionEditor #11283

Merged
merged 3 commits into from
May 29, 2024
Merged
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
4 changes: 3 additions & 1 deletion src/System.Windows.Forms.Design/src/Resources/SR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1623,5 +1623,7 @@ Press Ctrl+Enter to accept Text.</value>
<data name="DesignBindingPickerHelpNodeProjectGroup" xml:space="preserve">
<value>Contains project data sources belonging to this namespace.</value>
</data>

<data name="CollectionEditorCreateInstanceError" xml:space="preserve">
<value>Neither {0} nor {1} can create an instance of {2}.</value>
</data>
</root>
5 changes: 5 additions & 0 deletions src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,22 @@ protected virtual object CreateInstance(Type itemType)
}
}

return itemType.UnderlyingSystemType == typeof(string)
? string.Empty
: TypeDescriptor.CreateInstance(host, itemType, argTypes: null, args: null)!;
if (itemType.UnderlyingSystemType == typeof(string))
{
return string.Empty;
}

if (TypeDescriptor.CreateInstance(host, itemType, argTypes: null, args: null) is { } obj)
{
return obj;
}

throw new InvalidOperationException(
string.Format(
SR.CollectionEditorCreateInstanceError,
nameof(IDesignerHost),
nameof(TypeDescriptor),
itemType.FullName));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -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

using System.ComponentModel.Design;

namespace System.Windows.Forms.Design;
Expand All @@ -13,29 +11,31 @@ namespace System.Windows.Forms.Design;
/// </summary>
internal class TabPageCollectionEditor : CollectionEditor
{
public TabPageCollectionEditor() : base(typeof(TabControl.TabPageCollection))
public TabPageCollectionEditor()
: base(typeof(TabControl.TabPageCollection))
{
}

/// <summary>
/// Sets the specified collection to have the specified array of items.
/// </summary>
protected override object SetItems(object editValue, object[] value)
protected override object? SetItems(object? editValue, object[]? value)
{
var tabControl = Context.Instance as TabControl;
var tabControl = Context?.Instance as TabControl;
tabControl?.SuspendLayout();

object retValue = base.SetItems(editValue, value);
object? retValue = base.SetItems(editValue, value);

tabControl?.ResumeLayout();

return retValue;
}

protected override object CreateInstance(Type itemType)
{
object instance = base.CreateInstance(itemType);
LeafShi1 marked this conversation as resolved.
Show resolved Hide resolved

TabPage tabPage = instance as TabPage;
TabPage tabPage = (TabPage)instance;
tabPage.UseVisualStyleBackColor = true;

return tabPage;
Expand Down