Skip to content

Commit

Permalink
Refactor GetStandardValues implementations to remove ArrayList (#8276)
Browse files Browse the repository at this point in the history
* Refactor GetStandardValues implementations to remove ArrayList

* fix usings

* changes from review

* changes from review
  • Loading branch information
elachlan committed Dec 1, 2022
1 parent 3ab342e commit c872b6e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
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 @@ -5,6 +5,7 @@
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.ComponentModel;
using System.Diagnostics;

namespace System.Windows.Forms
{
Expand All @@ -23,23 +24,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 &&
object? currentItem = values[i];
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]);
Debug.Assert(currentItem is not null);
if (currentItem is not null)
{
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

0 comments on commit c872b6e

Please sign in to comment.