-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Refactor SnapLines
to use IList
directly instead of casting to ArrayList
#10279
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c5e4566
Refactor SnapLines to use IList directly instead of casting to ArrayList
elachlan eb3e6a1
Refactor Add ListAdapter and use IList<SnapLine>
elachlan d2117fd
Refactor to use IList<SnapLine>
elachlan 0d3c34f
Add IWrapper and AdapterHelpers and use them throughout
elachlan 691af86
Fix up missed usages of Unwrap
elachlan 2e31068
Extract out files and add comments
elachlan 6f5872e
Fix comment indent
elachlan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/AdapterHelpers.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections; | ||
|
||
namespace System.Windows.Forms.Design; | ||
|
||
/// <summary> | ||
/// Helpers for adapting between generic and non-generic lists. | ||
/// </summary> | ||
internal static class AdapterHelpers | ||
{ | ||
/// <summary> | ||
/// Provides an extension method to safely extract the underlying non-generic <see cref="IList"/> | ||
/// from a wrapped <see cref="IList<T>"/> when available. | ||
/// </summary> | ||
/// <typeparam name="T">The type of elements in the <see cref="IList<T>"/>.</typeparam> | ||
/// <param name="list">The IList<T> to unwrap.</param> | ||
/// <returns>The underlying non-generic <see cref="IList"/> if available; otherwise, the original <see cref="IList<T>"/>.</returns> | ||
internal static IList Unwrap<T>(this IList<T> list) => list is IWrapper<IList> wrapper ? wrapper.Unwrap() : (IList)list; | ||
|
||
/// <summary> | ||
/// Provides an extension method to adapt a non-generic IList to a generic <see cref="IList<T>"/> by creating | ||
/// a <see cref="ListAdapter<T>"/> when needed. | ||
/// </summary> | ||
/// <typeparam name="T">The desired type of elements in the resulting <see cref="IList<T>"/>.</typeparam> | ||
/// <param name="list">The non-generic <see cref="IList"/> to adapt.</param> | ||
/// <returns> | ||
/// A generic <see cref="IList<T>"/> if the input IList can be cast to <see cref="IList<T>"/> otherwise, a new <see cref="ListAdapter<T>"/> wrapping the input IList. | ||
/// </returns> | ||
internal static IList<T> Adapt<T>(this IList list) => list is IList<T> iList ? iList : new ListAdapter<T>(list); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/IWrapper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Windows.Forms.Design; | ||
|
||
/// <summary> | ||
/// Interface to provide a contract to provide access to the underlying type. | ||
/// </summary> | ||
/// <typeparam name="T">The type of object being wrapped.</typeparam> | ||
internal interface IWrapper<T> | ||
{ | ||
T Unwrap(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ListAdapter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections; | ||
|
||
namespace System.Windows.Forms.Design; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a blank line and comments for the class |
||
|
||
/// <summary> | ||
/// Adapter for bridging between generic and non-generic lists. | ||
/// It implements both the generic <see cref="IList<T>"/> and the non-generic | ||
/// <see cref="IWrapper<IList>"/> interfaces | ||
/// to provide a unified interface for working with IList collections. | ||
/// </summary> | ||
/// <typeparam name="T">The type of elements in the list.</typeparam> | ||
internal sealed class ListAdapter<T> : IList<T>, IWrapper<IList> | ||
{ | ||
private readonly IList _list; | ||
internal ListAdapter(IList list) => _list = list.OrThrowIfNull(); | ||
|
||
T IList<T>.this[int index] | ||
{ | ||
get => (T?)_list[index] ?? throw new InvalidOperationException(); | ||
set => _list[index] = value.OrThrowIfNull(); | ||
} | ||
|
||
int ICollection<T>.Count => _list.Count; | ||
|
||
bool ICollection<T>.IsReadOnly => _list.IsReadOnly; | ||
|
||
void ICollection<T>.Add(T item) => _list.Add(item.OrThrowIfNull()); | ||
void ICollection<T>.Clear() => _list.Clear(); | ||
bool ICollection<T>.Contains(T item) => _list.Contains(item); | ||
void ICollection<T>.CopyTo(T[] array, int arrayIndex) => _list.CopyTo(array, arrayIndex); | ||
IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator(); | ||
int IList<T>.IndexOf(T item) => _list.IndexOf(item); | ||
void IList<T>.Insert(int index, T item) => _list.Insert(index, item.OrThrowIfNull()); | ||
void IList<T>.RemoveAt(int index) => _list.RemoveAt(index); | ||
|
||
bool ICollection<T>.Remove(T item) | ||
{ | ||
if (_list.IsReadOnly || !_list.Contains(item)) | ||
{ | ||
return false; | ||
} | ||
|
||
_list.Remove(item); | ||
return true; | ||
} | ||
|
||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => new Enumerator(_list.GetEnumerator()); | ||
|
||
private sealed class Enumerator(IEnumerator _enumerator) : IEnumerator<T> | ||
{ | ||
T IEnumerator<T>.Current => (T)_enumerator.Current; | ||
object IEnumerator.Current => _enumerator.Current; | ||
|
||
void IDisposable.Dispose() { } | ||
bool IEnumerator.MoveNext() => _enumerator.MoveNext(); | ||
void IEnumerator.Reset() => _enumerator.Reset(); | ||
} | ||
|
||
public IList Unwrap() => _list; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure annotating
FlowPanelDesigner
for NRT should be part of this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure? Its a very small change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I though the parent class wasn't annotated, but apparently it is, so in that light it's a small change (though the parent's parent isn't, which exposes us to incorrect assumptions)