Remove duplicated code from SR.cs (#36277)
authorMarek Safar <marek.safar@gmail.com>
Tue, 19 May 2020 14:26:01 +0000 (16:26 +0200)
committerGitHub <noreply@github.com>
Tue, 19 May 2020 14:26:01 +0000 (16:26 +0200)
src/libraries/Common/src/System/SR.cs
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
src/libraries/System.Private.CoreLib/src/System/SR.cs

index 3574920..69a233e 100644 (file)
@@ -29,7 +29,12 @@ namespace System
             string? resourceString = null;
             try
             {
-                resourceString = ResourceManager.GetString(resourceKey);
+                resourceString =
+#if SYSTEM_PRIVATE_CORELIB
+                    InternalGetResourceString(resourceKey);
+#else
+                    ResourceManager.GetString(resourceKey);
+#endif
             }
             catch (MissingManifestResourceException) { }
 
index 23fd990..3ee0049 100644 (file)
     <Compile Include="$(CommonPath)System\HResults.cs">
       <Link>Common\System\HResults.cs</Link>
     </Compile>
+    <Compile Include="$(CommonPath)System\SR.cs">
+      <Link>Common\System\SR.cs</Link>
+    </Compile>
     <Compile Include="$(CommonPath)System\Collections\Generic\ReferenceEqualityComparer.cs">
       <Link>Common\System\Collections\Generic\ReferenceEqualityComparer.cs</Link>
     </Compile>
index e70d618..017ce55 100644 (file)
@@ -13,53 +13,24 @@ namespace System
 {
     internal static partial class SR
     {
-        // This method is used to decide if we need to append the exception message parameters to the message when calling SR.Format.
-        // by default it returns false.
-        // Native code generators can replace the value this returns based on user input at the time of native code generation.
-        // Marked as NoInlining because if this is used in an AoT compiled app that is not compiled into a single file, the user
-        // could compile each module with a different setting for this. We want to make sure there's a consistent behavior
-        // that doesn't depend on which native module this method got inlined into.
-        [MethodImpl(MethodImplOptions.NoInlining)]
-        private static bool UsingResourceKeys()
-        {
-            return false;
-        }
+        private static readonly object _lock = new object();
+        private static List<string>? _currentlyLoading;
+        private static int _infinitelyRecursingCount;
+        private static bool _resourceManagerInited;
 
         // Needed for debugger integration
-        internal static string? GetResourceString(string resourceKey)
+        internal static string GetResourceString(string resourceKey)
         {
             return GetResourceString(resourceKey, string.Empty);
         }
 
-        internal static string GetResourceString(string resourceKey, string? defaultString)
-        {
-            if (UsingResourceKeys())
-                return defaultString ?? resourceKey;
-
-            string? resourceString = null;
-            try { resourceString = InternalGetResourceString(resourceKey); }
-            catch (MissingManifestResourceException) { }
-
-            if (defaultString != null && resourceKey.Equals(resourceString, StringComparison.Ordinal))
-            {
-                return defaultString;
-            }
-
-            return resourceString!; // only null if missing resource
-        }
-
-        private static readonly object _lock = new object();
-        private static List<string>? _currentlyLoading;
-        private static int _infinitelyRecursingCount;
-        private static bool _resourceManagerInited = false;
-
         [PreserveDependency(".cctor()", "System.Resources.ResourceManager")]
-        private static string? InternalGetResourceString(string? key)
+        private static string InternalGetResourceString(string key)
         {
-            if (string.IsNullOrEmpty(key))
+            if (key.Length == 0)
             {
-                Debug.Fail("SR::GetResourceString with null or empty key.  Bug in caller, or weird recursive loading problem?");
-                return key!;
+                Debug.Fail("SR::GetResourceString with empty resourceKey.  Bug in caller, or weird recursive loading problem?");
+                return key;
             }
 
             // We have a somewhat common potential for infinite
@@ -146,64 +117,5 @@ namespace System
                 }
             }
         }
-
-        internal static string Format(IFormatProvider? provider, string resourceFormat, params object?[]? args)
-        {
-            if (args != null)
-            {
-                if (UsingResourceKeys())
-                {
-                    return resourceFormat + ", " + string.Join(", ", args);
-                }
-
-                return string.Format(provider, resourceFormat, args);
-            }
-
-            return resourceFormat;
-        }
-
-        internal static string Format(string resourceFormat, params object?[]? args)
-        {
-            if (args != null)
-            {
-                if (UsingResourceKeys())
-                {
-                    return resourceFormat + ", " + string.Join(", ", args);
-                }
-
-                return string.Format(resourceFormat, args);
-            }
-
-            return resourceFormat;
-        }
-
-        internal static string Format(string resourceFormat, object? p1)
-        {
-            if (UsingResourceKeys())
-            {
-                return string.Join(", ", resourceFormat, p1);
-            }
-
-            return string.Format(resourceFormat, p1);
-        }
-
-        internal static string Format(string resourceFormat, object? p1, object? p2)
-        {
-            if (UsingResourceKeys())
-            {
-                return string.Join(", ", resourceFormat, p1, p2);
-            }
-
-            return string.Format(resourceFormat, p1, p2);
-        }
-
-        internal static string Format(string resourceFormat, object? p1, object? p2, object? p3)
-        {
-            if (UsingResourceKeys())
-            {
-                return string.Join(", ", resourceFormat, p1, p2, p3);
-            }
-            return string.Format(resourceFormat, p1, p2, p3);
-        }
     }
 }