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

Refactor GetStandardValues implementations to remove ArrayList #8276

Merged
merged 4 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -119,7 +119,7 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex

if (needMassage)
{
ArrayList list = new ArrayList(values.Count);
List<MemberAttributes> list = new(values.Count);

foreach (MemberAttributes value in values)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
Expand Down Expand Up @@ -164,17 +163,20 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex
{
if (_values is null)
{
ArrayList list = new ArrayList();
List<object> list = new();
PropertyInfo[] props = GetProperties();
for (int i = 0; i < props.Length; i++)
{
PropertyInfo prop = props[i];
object[]? tempIndex = null;
Debug.Assert(prop.GetValue(null, tempIndex) is not null, "Property " + prop.Name + " returned NULL");
list.Add(prop.GetValue(null, tempIndex));
Debug.Assert(prop.GetValue(null, tempIndex) is not null, $"Property {prop.Name} returned NULL");
if (prop.GetValue(null, tempIndex) is object item)
{
list.Add(item);
}
}

_values = new StandardValuesCollection(list.ToArray());
_values = new StandardValuesCollection(list);
}

return _values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System.Collections;
using System.ComponentModel;

namespace System.Windows.Forms
Expand All @@ -19,14 +16,13 @@ public MdiWindowListItemConverter(Type type) : base(type)
/// Gets a collection of standard values for the data type this validator is
/// designed for.
/// </summary>
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext? context)
{
if (context.Instance is MenuStrip menu)
if (context?.Instance is MenuStrip menu)
{
StandardValuesCollection values = base.GetStandardValues(context);
ArrayList list = new ArrayList();
int count = values.Count;
for (int i = 0; i < count; i++)
List<ToolStripItem> list = new();
for (int i = 0; i < values.Count; i++)
{
if (values[i] is ToolStripItem currentItem && currentItem.Owner == menu)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,27 @@ public SpecialFolderEnumConverter(
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext? context)
{
StandardValuesCollection values = base.GetStandardValues(context);
var list = new ArrayList();
int count = values.Count;
List<object> list = new();
bool personalSeen = false;
for (int i = 0; i < count; i++)
for (int i = 0; i < values.Count; i++)
{
if (values[i] is Environment.SpecialFolder specialFolder &&
if (values[i] is not object currentItem)
dreddy-work marked this conversation as resolved.
Show resolved Hide resolved
{
continue;
}

if (currentItem is Environment.SpecialFolder specialFolder &&
specialFolder.Equals(Environment.SpecialFolder.Personal))
{
if (!personalSeen)
{
personalSeen = true;
list.Add(values[i]);
list.Add(currentItem);
}
}
else
{
list.Add(values[i]);
list.Add(currentItem);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;

namespace System.Windows.Forms
{
Expand All @@ -22,17 +19,18 @@ public TextBoxAutoCompleteSourceConverter(
/// Gets a collection of standard values for the data type this validator is
/// designed for.
/// </summary>
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext? context)
{
StandardValuesCollection values = base.GetStandardValues(context);
ArrayList list = new ArrayList();
int count = values.Count;
for (int i = 0; i < count; i++)
List<object> list = new();
for (int i = 0; i < values.Count; i++)
{
string currentItemText = values[i].ToString();
if (!currentItemText.Equals("ListItems"))
if (values[i] is object currentItem)
{
list.Add(values[i]);
if (string.Equals(currentItem.ToString(), "ListItems"))
{
list.Add(currentItem);
}
}
}

Expand Down