-
Notifications
You must be signed in to change notification settings - Fork 982
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
WIP: implement generic IList interface #2749
Closed
Closed
Changes from all commits
Commits
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
This file contains 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 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 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 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#nullable disable | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Drawing; | ||
|
@@ -1093,7 +1094,7 @@ public int Add(object item, CheckState check) | |
} | ||
} | ||
|
||
public class CheckedIndexCollection : IList | ||
public class CheckedIndexCollection : IList, IList<int> | ||
{ | ||
private readonly CheckedListBox owner; | ||
|
||
|
@@ -1171,26 +1172,57 @@ object IList.this[int index] | |
} | ||
} | ||
|
||
int IList<int>.this[int index] | ||
{ | ||
get => this[index]; | ||
set => throw new NotSupportedException(SR.CheckedListBoxCheckedIndexCollectionIsReadOnly); | ||
} | ||
|
||
void ICollection<int>.Add(int value) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedIndexCollectionIsReadOnly); | ||
} | ||
|
||
int IList.Add(object value) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedIndexCollectionIsReadOnly); | ||
} | ||
|
||
void ICollection<int>.Clear() | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedIndexCollectionIsReadOnly); | ||
} | ||
|
||
void IList.Clear() | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedIndexCollectionIsReadOnly); | ||
} | ||
|
||
void IList<int>.Insert(int index, int value) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedIndexCollectionIsReadOnly); | ||
} | ||
|
||
void IList.Insert(int index, object value) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedIndexCollectionIsReadOnly); | ||
} | ||
|
||
bool ICollection<int>.Remove(int value) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedIndexCollectionIsReadOnly); | ||
} | ||
|
||
void IList.Remove(object value) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedIndexCollectionIsReadOnly); | ||
} | ||
|
||
void IList<int>.RemoveAt(int index) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedIndexCollectionIsReadOnly); | ||
} | ||
|
||
void IList.RemoveAt(int index) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedIndexCollectionIsReadOnly); | ||
|
@@ -1222,6 +1254,8 @@ public void CopyTo(Array dest, int index) | |
} | ||
} | ||
|
||
void ICollection<int>.CopyTo(int[] array, int index) => CopyTo(array, index); | ||
|
||
/// <summary> | ||
/// This is the item array that stores our data. We share this backing store | ||
/// with the main object collection. | ||
|
@@ -1234,11 +1268,13 @@ private ItemArray InnerArray | |
} | ||
} | ||
|
||
public IEnumerator GetEnumerator() | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
|
||
public IEnumerator<int> GetEnumerator() | ||
{ | ||
int[] indices = new int[Count]; | ||
CopyTo(indices, 0); | ||
return indices.GetEnumerator(); | ||
return WindowsFormsUtils.GetArrayEnumerator(indices); | ||
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. Getting the generic |
||
} | ||
|
||
public int IndexOf(int index) | ||
|
@@ -1264,7 +1300,7 @@ int IList.IndexOf(object index) | |
} | ||
} | ||
|
||
public class CheckedItemCollection : IList | ||
public class CheckedItemCollection : IList, IList<object> | ||
{ | ||
internal static int CheckedItemMask = ItemArray.CreateMask(); | ||
internal static int IndeterminateItemMask = ItemArray.CreateMask(); | ||
|
@@ -1364,26 +1400,51 @@ internal int IndexOfIdentifier(object item) | |
return InnerArray.IndexOfIdentifier(item, AnyMask); | ||
} | ||
|
||
void ICollection<object>.Add(object value) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedItemCollectionIsReadOnly); | ||
} | ||
|
||
int IList.Add(object value) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedItemCollectionIsReadOnly); | ||
} | ||
|
||
void ICollection<object>.Clear() | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedItemCollectionIsReadOnly); | ||
} | ||
|
||
void IList.Clear() | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedItemCollectionIsReadOnly); | ||
} | ||
|
||
void IList<object>.Insert(int index, object value) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedItemCollectionIsReadOnly); | ||
} | ||
|
||
void IList.Insert(int index, object value) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedItemCollectionIsReadOnly); | ||
} | ||
|
||
bool ICollection<object>.Remove(object value) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedItemCollectionIsReadOnly); | ||
} | ||
|
||
void IList.Remove(object value) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedItemCollectionIsReadOnly); | ||
} | ||
|
||
void IList<object>.RemoveAt(int index) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedItemCollectionIsReadOnly); | ||
} | ||
|
||
void IList.RemoveAt(int index) | ||
{ | ||
throw new NotSupportedException(SR.CheckedListBoxCheckedItemCollectionIsReadOnly); | ||
|
@@ -1398,6 +1459,8 @@ public void CopyTo(Array dest, int index) | |
} | ||
} | ||
|
||
void ICollection<object>.CopyTo(object[] dest, int index) => CopyTo(dest, index); | ||
|
||
/// <summary> | ||
/// This method returns if the actual item index is checked. The index is the index to the MAIN | ||
/// collection, not this one. | ||
|
@@ -1419,7 +1482,9 @@ internal CheckState GetCheckedState(int index) | |
return CheckState.Unchecked; | ||
} | ||
|
||
public IEnumerator GetEnumerator() | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
|
||
public IEnumerator<object> GetEnumerator() | ||
{ | ||
return InnerArray.GetEnumerator(AnyMask, true); | ||
} | ||
|
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.
In this PR iteration instead of changing return type of public
Remove
methods I instead add a privateTryRemove
method to avoid code duplication so that interfaces can use the same call.