Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 71dc688

Browse files
benaadamsjkotas
authored andcommitted
Externalize exception boxing (#15418)
1 parent 12ab7fc commit 71dc688

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/mscorlib/src/System/ThrowHelper.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,29 +100,33 @@ internal static void ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count()
100100
ExceptionResource.ArgumentOutOfRange_Count);
101101
}
102102

103-
internal static void ThrowWrongKeyTypeArgumentException(object key, Type targetType)
103+
internal static void ThrowWrongKeyTypeArgumentException<T>(T key, Type targetType)
104104
{
105-
throw GetWrongKeyTypeArgumentException(key, targetType);
105+
// Generic key to move the boxing to the right hand side of throw
106+
throw GetWrongKeyTypeArgumentException((object)key, targetType);
106107
}
107108

108-
internal static void ThrowWrongValueTypeArgumentException(object value, Type targetType)
109+
internal static void ThrowWrongValueTypeArgumentException<T>(T value, Type targetType)
109110
{
110-
throw GetWrongValueTypeArgumentException(value, targetType);
111+
// Generic key to move the boxing to the right hand side of throw
112+
throw GetWrongValueTypeArgumentException((object)value, targetType);
111113
}
112114

113115
private static ArgumentException GetAddingDuplicateWithKeyArgumentException(object key)
114116
{
115117
return new ArgumentException(SR.Format(SR.Argument_AddingDuplicateWithKey, key));
116118
}
117119

118-
internal static void ThrowAddingDuplicateWithKeyArgumentException(object key)
120+
internal static void ThrowAddingDuplicateWithKeyArgumentException<T>(T key)
119121
{
120-
throw GetAddingDuplicateWithKeyArgumentException(key);
122+
// Generic key to move the boxing to the right hand side of throw
123+
throw GetAddingDuplicateWithKeyArgumentException((object)key);
121124
}
122125

123-
internal static void ThrowKeyNotFoundException(object key)
126+
internal static void ThrowKeyNotFoundException<T>(T key)
124127
{
125-
throw GetKeyNotFoundException(key);
128+
// Generic key to move the boxing to the right hand side of throw
129+
throw GetKeyNotFoundException((object)key);
126130
}
127131

128132
internal static void ThrowArgumentException(ExceptionResource resource)

0 commit comments

Comments
 (0)