Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3673ca2

Browse files
committed
Fix incorrect param name
1. Fix incorrect param name in ArgumentOutOfRangeException.
1 parent e7188aa commit 3673ca2

File tree

2 files changed

+103
-6
lines changed

2 files changed

+103
-6
lines changed

‎src/AlgorithmForce.Searching/Deferred/EnumerableExtensions.cs‎

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static int IndexOf<T>(this IEnumerable<T> s, IReadOnlyList<T> t, int star
9797
public static int IndexOf<T>(this IEnumerable<T> s, IReadOnlyList<T> t, int startIndex, IEqualityComparer<T> comparer)
9898
where T : IEquatable<T>
9999
{
100-
Validate(s, t);
100+
Validate(s, t,startIndex);
101101

102102
// Follow the behavior of string.IndexOf(string) method.
103103
if (t.Count == 0) return 0;
@@ -142,6 +142,102 @@ public static int IndexOf<T>(this IEnumerable<T> s, IReadOnlyList<T> t, int star
142142
return -1;
143143
}
144144

145+
146+
#region IReadOnlyList(T) (IndexesOf)
147+
148+
/// <summary>
149+
/// Enumerates each zero-based index of all occurrences of the specified collection in this instance.
150+
/// </summary>
151+
/// <param name="s">The current collection.</param>
152+
/// <param name="t">The collection to seek.</param>
153+
/// <typeparam name="T">The type of element in the collection.</typeparam>
154+
/// <returns>
155+
/// The zero-based index positions of value if one or more <paramref name="t"/> are found.
156+
/// If <paramref name="t"/> is empty, no indexes will be enumerated.
157+
/// </returns>
158+
/// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception>
159+
public static IEnumerable<int> IndexesOf<T>(this IEnumerable<T> s, IReadOnlyList<T> t)
160+
where T : IEquatable<T>
161+
{
162+
return s.IndexesOf(t, 0, EqualityComparer<T>.Default);
163+
}
164+
165+
/// <summary>
166+
/// Enumerates each zero-based index of all occurrences of the specified collection in this instance
167+
/// and uses the specified <see cref="IEqualityComparer{T}"/>.
168+
/// </summary>
169+
/// <param name="s">The current collection.</param>
170+
/// <param name="t">The collection to seek.</param>
171+
/// <param name="comparer">The specified <see cref="IEqualityComparer{T}"/> instance.</param>
172+
/// <typeparam name="T">The type of element in the collection.</typeparam>
173+
/// <returns>
174+
/// The zero-based index positions of value if one or more <paramref name="t"/> are found.
175+
/// If <paramref name="t"/> is empty, no indexes will be enumerated.
176+
/// </returns>
177+
/// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception>
178+
public static IEnumerable<int> IndexesOf<T>(this IEnumerable<T> s, IReadOnlyList<T> t, IEqualityComparer<T> comparer)
179+
where T : IEquatable<T>
180+
{
181+
return s.IndexesOf(t, 0, comparer);
182+
}
183+
184+
/// <summary>
185+
/// Enumerates each zero-based index of all occurrences of the specified collection in this instance.
186+
/// The search starts at a specified position.
187+
/// </summary>
188+
/// <param name="s">The current collection.</param>
189+
/// <param name="t">The collection to seek.</param>
190+
/// <param name="startIndex">The search starting position.</param>
191+
/// <typeparam name="T">The type of element in the collection.</typeparam>
192+
/// <returns>
193+
/// The zero-based index positions of value if one or more <paramref name="t"/> are found.
194+
/// If <paramref name="t"/> is empty, no indexes will be enumerated.
195+
/// </returns>
196+
/// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception>
197+
/// <exception cref="ArgumentOutOfRangeException">
198+
/// <paramref name="startIndex"/> is less than zero.
199+
/// </exception>
200+
public static IEnumerable<int> IndexesOf<T>(this IEnumerable<T> s, IReadOnlyList<T> t, int startIndex)
201+
where T : IEquatable<T>
202+
{
203+
return s.IndexesOf(t, startIndex, EqualityComparer<T>.Default);
204+
}
205+
206+
/// <summary>
207+
/// Enumerates each zero-based index of all occurrences of the specified collection in this instance
208+
/// and uses the specified <see cref="IEqualityComparer{T}"/>.
209+
/// The search starts at a specified position.
210+
/// </summary>
211+
/// <param name="s">The current collection.</param>
212+
/// <param name="t">The collection to seek.</param>
213+
/// <param name="startIndex">The search starting position.</param>
214+
/// <param name="comparer">The specified <see cref="IEqualityComparer{T}"/> instance.</param>
215+
/// <typeparam name="T">The type of element in the collection.</typeparam>
216+
/// <returns>
217+
/// The zero-based index positions of value if one or more <paramref name="t"/> are found.
218+
/// If <paramref name="t"/> is empty, no indexes will be enumerated.
219+
/// </returns>
220+
/// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception>
221+
/// <exception cref="ArgumentOutOfRangeException">
222+
/// <paramref name="startIndex"/> is less than zero.
223+
/// </exception>
224+
public static IEnumerable<int> IndexesOf<T>(this IEnumerable<T> s, IReadOnlyList<T> t, int startIndex, IEqualityComparer<T> comparer)
225+
where T : IEquatable<T>
226+
{
227+
Validate(s, t, startIndex);
228+
229+
if (comparer == null) comparer = EqualityComparer<T>.Default;
230+
if (t.Count == 1)
231+
return EnumerateIndexes(s, t[0], startIndex, comparer);
232+
else
233+
return EnumerateIndexes(s, t, startIndex, comparer);
234+
}
235+
236+
237+
#endregion
238+
239+
#region Others
240+
145241
internal static IEnumerable<int> EnumerateIndexes<T>(this IEnumerable<T> s, IReadOnlyList<T> t, int startIndex, IEqualityComparer<T> comparer)
146242
where T : IEquatable<T>
147243
{
@@ -193,8 +289,6 @@ internal static IEnumerable<int> EnumerateIndexes<T>(this IEnumerable<T> s, IRea
193289

194290
#endregion
195291

196-
#region Others
197-
198292
internal static int IndexOf<T>(this IEnumerable<T> s, T t, int startIndex, IEqualityComparer<T> comparer)
199293
where T : IEquatable<T>
200294
{
@@ -245,10 +339,13 @@ internal static IEnumerator<T> Skip<T>(IEnumerator<T> enumerator, int count)
245339
return enumerator;
246340
}
247341

248-
internal static void Validate<T>(IEnumerable<T> s, IReadOnlyList<T> t)
342+
internal static void Validate<T>(IEnumerable<T> s, IReadOnlyList<T> t,intstartIndex)
249343
{
250344
if (s == null) throw new ArgumentNullException(nameof(s));
251345
if (t == null) throw new ArgumentNullException(nameof(t));
346+
347+
if (startIndex < 0)
348+
throw new ArgumentOutOfRangeException(nameof(startIndex), "Value is less than zero.");
252349
}
253350

254351
#endregion

‎src/AlgorithmForce.Searching/Extensions.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,10 +846,10 @@ internal static void Validate<T>(IReadOnlyList<T> s, IReadOnlyList<T> t, int sta
846846
if (t == null) throw new ArgumentNullException(nameof(t));
847847

848848
if (startIndex < 0)
849-
throw new ArgumentOutOfRangeException(nameof(s), "Value is less than zero.");
849+
throw new ArgumentOutOfRangeException(nameof(startIndex), "Value is less than zero.");
850850

851851
if (startIndex >= s.Count)
852-
throw new ArgumentOutOfRangeException(nameof(s), "Value is greater than the length of s.");
852+
throw new ArgumentOutOfRangeException(nameof(startIndex), "Value is greater than the length of s.");
853853
}
854854

855855
internal static int IndexOf<T>(this IReadOnlyList<T> s, T t, int startIndex, IEqualityComparer<T> comparer)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /