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 ArrangedElementCollection to replace ArrayList #8202

Closed
Closed
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 @@ -12,22 +12,22 @@ public class ArrangedElementCollection : IList

internal ArrangedElementCollection()
{
InnerList = new ArrayList(4);
InnerList = new(4);
}

internal ArrangedElementCollection(ArrayList innerList)
internal ArrangedElementCollection(List<IArrangedElement> innerList)
{
InnerList = innerList;
}

private ArrangedElementCollection(int size)
{
InnerList = new ArrayList(size);
InnerList = new(size);
}

private protected ArrayList InnerList { get; }
private protected List<IArrangedElement> InnerList { get; }

internal virtual IArrangedElement this[int index] => (IArrangedElement)InnerList[index]!;
internal virtual IArrangedElement this[int index] => InnerList[index]!;

public override bool Equals(object? obj)
{
Expand Down Expand Up @@ -127,19 +127,28 @@ private static void Copy(ArrangedElementCollection sourceList, int sourceIndex,

void IList.Clear() => InnerList.Clear();

bool IList.IsFixedSize => InnerList.IsFixedSize;
bool IList.IsFixedSize => false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property is causing issues as classes that inherit from this can't see it. The compiler complains when I try changing it.


bool IList.Contains(object? value) => InnerList.Contains(value);

public virtual bool IsReadOnly => InnerList.IsReadOnly;
public virtual bool IsReadOnly => false;

void IList.RemoveAt(int index) => InnerList.RemoveAt(index);

void IList.Remove(object? value) => InnerList.Remove(value);
void IList.Remove(object? value) => InnerList.Remove((IArrangedElement)value);

int IList.Add(object? value) => InnerList.Add(value);
int IList.Add(object? value)
{
if (value is not null and IArrangedElement)
{
InnerList.Add((IArrangedElement)value);
return InnerList.Count - 1;
}

return -1;
}

int IList.IndexOf(object? value) => InnerList.IndexOf(value);
int IList.IndexOf(object? value) => InnerList.IndexOf((IArrangedElement)value);

void IList.Insert(int index, object? value) => throw new NotSupportedException();

Expand All @@ -151,11 +160,11 @@ private static void Copy(ArrangedElementCollection sourceList, int sourceIndex,

public virtual int Count => InnerList.Count;

object ICollection.SyncRoot => InnerList.SyncRoot;
object ICollection.SyncRoot => ((ICollection)InnerList).SyncRoot;

public void CopyTo(Array array, int index) => InnerList.CopyTo(array, index);
public void CopyTo(Array array, int index) => InnerList.CopyTo((IArrangedElement[])array, index);

bool ICollection.IsSynchronized => InnerList.IsSynchronized;
bool ICollection.IsSynchronized => ((ICollection)InnerList).IsSynchronized;

public virtual IEnumerator GetEnumerator() => InnerList.GetEnumerator();
}
Expand Down