Skip to content

Commit f1c5c03

Browse files
committed
Use Unsafe.As for generic cast
1 parent b622b6b commit f1c5c03

File tree

1 file changed

+2
-2
lines changed
  • src/libraries/System.Private.CoreLib/src/System/Collections/Generic

1 file changed

+2
-2
lines changed

src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private void AddRange(IEnumerable<KeyValuePair<TKey, TValue>> enumerable)
116116
// back-compat with subclasses that may have overridden the enumerator behavior.
117117
if (enumerable.GetType() == typeof(Dictionary<TKey, TValue>))
118118
{
119-
Dictionary<TKey, TValue> source = (Dictionary<TKey, TValue>)enumerable;
119+
Dictionary<TKey, TValue> source = Unsafe.As<Dictionary<TKey, TValue>>(enumerable);
120120

121121
if (source.Count == 0)
122122
{
@@ -161,7 +161,7 @@ private void AddRange(IEnumerable<KeyValuePair<TKey, TValue>> enumerable)
161161
}
162162
else if (enumerable.GetType() == typeof(List<KeyValuePair<TKey, TValue>>))
163163
{
164-
span = CollectionsMarshal.AsSpan((List<KeyValuePair<TKey, TValue>>)enumerable);
164+
span = CollectionsMarshal.AsSpan(Unsafe.As<List<KeyValuePair<TKey, TValue>>>(enumerable));
165165
}
166166
else
167167
{

0 commit comments

Comments
 (0)