Skip to content

Commit 401653c

Browse files
Implement Core support
1 parent 4537486 commit 401653c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/NHibernate/Collection/Generic/SetHelpers/SetSnapShot.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,26 @@ protected SetSnapShot(SerializationInfo info, StreamingContext context) : base(i
157157

158158
void ICollection.CopyTo(Array array, int index)
159159
{
160-
if (!(array is T[] typedArray))
160+
if (array is T[] typedArray)
161161
{
162-
throw new ArgumentException($"Array must be of type {typeof(T[])}.", nameof(array));
162+
CopyTo(typedArray, index);
163+
return;
163164
}
164165

165-
CopyTo(typedArray, index);
166+
if (array == null)
167+
throw new ArgumentNullException(nameof(array));
168+
169+
if (index < 0)
170+
throw new ArgumentOutOfRangeException(nameof(index), index, "Array index cannot be negative");
171+
172+
if (index > array.Length || Count > array.Length - index)
173+
throw new ArgumentException("Provided array is too small", nameof(array));
174+
175+
foreach (var value in this)
176+
{
177+
array.SetValue(value, index);
178+
index++;
179+
}
166180
}
167181

168182
bool ICollection.IsSynchronized => false;

0 commit comments

Comments
 (0)