Mono friendly System.Resources
authorMarek Safar <marek.safar@gmail.com>
Mon, 23 Mar 2015 15:47:56 +0000 (16:47 +0100)
committerMarek Safar <marek.safar@gmail.com>
Mon, 2 May 2016 22:08:05 +0000 (00:08 +0200)
mcs/class/referencesource/mscorlib/system/resources/manifestbasedresourcegroveler.cs
mcs/class/referencesource/mscorlib/system/resources/resourcemanager.cs
mcs/class/referencesource/mscorlib/system/resources/resourcewriter.cs

index 0b469000ccca2078bf1099bc2d5eef14191f27d1..9453aa60f8a6e9929eb58fb69ef4efe9cb3d4fb8 100644 (file)
@@ -255,9 +255,14 @@ namespace System.Resources {
             Contract.Assert(a != null, "assembly != null");
             string cultureName = null;
             short fallback = 0;
+
+#if MONO
+            if (GetNeutralResourcesLanguageAttribute(a, ref cultureName, ref fallback)) {
+#else
             if (GetNeutralResourcesLanguageAttribute(((RuntimeAssembly)a).GetNativeHandle(), 
                                                         JitHelpers.GetStringHandleOnStack(ref cultureName), 
                                                         out fallback)) {
+#endif
                 if ((UltimateResourceFallbackLocation)fallback < UltimateResourceFallbackLocation.MainAssembly || (UltimateResourceFallbackLocation)fallback > UltimateResourceFallbackLocation.Satellite) {
                     throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", fallback));
                 }
@@ -718,11 +723,24 @@ namespace System.Resources {
             throw new MissingManifestResourceException(Environment.GetResourceString("MissingManifestResource_NoNeutralAsm", resName, _mediator.MainAssembly.GetSimpleName()));
         }
 
+#if MONO
+        static bool GetNeutralResourcesLanguageAttribute (Assembly assembly, ref string cultureName, ref short fallbackLocation)
+        {
+            var ca = assembly.GetCustomAttribute<NeutralResourcesLanguageAttribute> ();
+            if (ca == null)
+                return false;
+
+            cultureName = ca.CultureName;
+            fallbackLocation = (short) ca.Location;
+            return true;
+        }
+#else
             [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
             [System.Security.SecurityCritical]  // Our security team doesn't yet allow safe-critical P/Invoke methods.
             [ResourceExposure(ResourceScope.None)]
             [System.Security.SuppressUnmanagedCodeSecurity]
             [return: MarshalAs(UnmanagedType.Bool)]
             internal static extern bool GetNeutralResourcesLanguageAttribute(RuntimeAssembly assemblyHandle, StringHandleOnStack cultureName, out short fallbackLocation);
+#endif
     }
 }
index 6173b5ba13acccd75afc0b2340e1397118fedafe..758f36b734633b8811940e15740456d3f6f8667e 100644 (file)
@@ -516,9 +516,10 @@ namespace System.Resources {
 
             _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, ref _fallbackLoc);
 
-#if !FEATURE_CORECLR && !MONO   // PAL doesn't support eventing, and we don't compile event providers for coreclr
+#if !FEATURE_CORECLR   // PAL doesn't support eventing, and we don't compile event providers for coreclr
             if (_bUsingModernResourceManagement == false)
             {
+#if !MONO
                 if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled()) {
                     CultureInfo culture = CultureInfo.InvariantCulture;
                     String defaultResName = GetResourceFileName(culture);
@@ -533,7 +534,7 @@ namespace System.Resources {
                         FrameworkEventSource.Log.ResourceManagerNeutralResourcesNotFound(BaseNameField, MainAssembly, outputResName);
                     }
                 }
-
+#endif
 #pragma warning disable 618
                 ResourceSets = new Hashtable(); // for backward compatibility
 #pragma warning restore 618
index 56b84ac25a33b15e6c2ed05666576eba1432aac2..76be4301836f48f5f0f7d17a5b96baf93af323a1 100644 (file)
@@ -94,7 +94,7 @@ namespace System.Resources {
         private const int AverageValueSize = 40;
 
         private Dictionary<String, Object> _resourceList;
-        private Stream _output;
+        internal Stream _output;
         private Dictionary<String, Object> _caseInsensitiveDups;
         private Dictionary<String, PrecannedResource> _preserializedData;
         private const int _DefaultBufferSize = 4096;