Skip to content

Commit 10c1f41

Browse files
SImplify code and handle Core code
1 parent 2ee3513 commit 10c1f41

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

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

+9-13
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,10 @@ void ICollection.CopyTo(Array array, int index)
120120
return;
121121
}
122122

123-
if (array.GetType().GetElementType().IsAssignableFrom(typeof(T)))
124-
{
125-
if (_hasNull)
126-
array.SetValue(default(T), index);
127-
ICollection keysCollection = _values.Keys;
128-
keysCollection.CopyTo(array, index + (_hasNull ? 1 : 0));
129-
return;
130-
}
131-
132-
throw new ArgumentException($"Array must be of type {typeof(T[])}.", nameof(array));
123+
if (_hasNull)
124+
array.SetValue(default(T), index);
125+
ICollection keysCollection = _values.Keys;
126+
keysCollection.CopyTo(array, index + (_hasNull ? 1 : 0));
133127
}
134128

135129
public int Count => _values.Count + (_hasNull ? 1 : 0);
@@ -163,12 +157,14 @@ protected SetSnapShot(SerializationInfo info, StreamingContext context) : base(i
163157

164158
void ICollection.CopyTo(Array array, int index)
165159
{
166-
if (!(array is T[] typedArray))
160+
if (array is T[] typedArray)
167161
{
168-
throw new ArgumentException($"Array must be of type {typeof(T[])}.", nameof(array));
162+
CopyTo(typedArray, index);
163+
return;
169164
}
170165

171-
CopyTo(typedArray, index);
166+
ICollection collection = this;
167+
collection.CopyTo(array, index);
172168
}
173169

174170
bool ICollection.IsSynchronized => false;

0 commit comments

Comments
 (0)