Address PR feedback for change adding key to KeyNotFoundException (#15234)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Wed, 6 Dec 2017 07:09:24 +0000 (23:09 -0800)
committerJan Kotas <jkotas@microsoft.com>
Wed, 6 Dec 2017 07:09:24 +0000 (02:09 -0500)
* Throwing KeyNotFoundException using Throw + get for JIT to generate better code for ii

src/mscorlib/Resources/Strings.resx
src/mscorlib/src/System/ThrowHelper.cs

index 79f9339..38d0f51 100644 (file)
   <data name="Arg_KeyNotFound" xml:space="preserve">
     <value>The given key was not present in the dictionary.</value>
   </data>
-    <data name="Arg_KeyNotFoundWithKey" xml:space="preserve">
+  <data name="Arg_KeyNotFoundWithKey" xml:space="preserve">
     <value>The given key '{0}' was not present in the dictionary.</value>
   </data>
   <data name="Arg_LongerThanDestArray" xml:space="preserve">
index 23b0e69..5a451e3 100644 (file)
@@ -122,7 +122,7 @@ namespace System
 
         internal static void ThrowKeyNotFoundException(object key)
         {
-            throw new KeyNotFoundException(key.ToString());
+            throw GetKeyNotFoundException(key);
         }
 
         internal static void ThrowArgumentException(ExceptionResource resource)
@@ -303,6 +303,11 @@ namespace System
             return new ArgumentException(SR.Format(SR.Arg_WrongType, value, targetType), nameof(value));
         }
 
+        private static KeyNotFoundException GetKeyNotFoundException(object key)
+        {
+            return new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
+        }
+
         internal static ArgumentOutOfRangeException GetArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
         {
             return new ArgumentOutOfRangeException(GetArgumentName(argument), GetResourceString(resource));