Beispiel #1
0
        internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, ref UltimateResourceFallbackLocation fallbackLocation)
        {
            string s = (string)null;
            short  fallbackLocation1 = 0;

            if (ManifestBasedResourceGroveler.GetNeutralResourcesLanguageAttribute(((RuntimeAssembly)a).GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref s), out fallbackLocation1))
            {
                if ((int)fallbackLocation1 < 0 || (int)fallbackLocation1 > 1)
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", (object)fallbackLocation1));
                }
                fallbackLocation = (UltimateResourceFallbackLocation)fallbackLocation1;
                try
                {
                    return(CultureInfo.GetCultureInfo(s));
                }
                catch (ArgumentException ex)
                {
                    if (a == typeof(object).Assembly)
                    {
                        return(CultureInfo.InvariantCulture);
                    }
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_Asm_Culture", (object)a.ToString(), (object)s), (Exception)ex);
                }
            }
            else
            {
                if (FrameworkEventSource.IsInitialized)
                {
                    FrameworkEventSource.Log.ResourceManagerNeutralResourceAttributeMissing(a);
                }
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return(CultureInfo.InvariantCulture);
            }
        }
        private void CommonSatelliteAssemblyInit()
        {
            this.UseManifest   = true;
            this._resourceSets = new Dictionary <string, ResourceSet>();
            this._fallbackLoc  = UltimateResourceFallbackLocation.MainAssembly;
            ResourceManagerMediator mediator = new ResourceManagerMediator(this);

            this.resourceGroveler         = new ManifestBasedResourceGroveler(mediator);
            this._neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(this.MainAssembly, ref this._fallbackLoc);
            if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled())
            {
                CultureInfo invariantCulture = CultureInfo.InvariantCulture;
                string      resourceFileName = this.GetResourceFileName(invariantCulture);
                if (this.resourceGroveler.HasNeutralResources(invariantCulture, resourceFileName))
                {
                    FrameworkEventSource.Log.ResourceManagerNeutralResourcesFound(this.BaseNameField, this.MainAssembly, resourceFileName);
                }
                else
                {
                    string resName = resourceFileName;
                    if ((this._locationInfo != null) && (this._locationInfo.Namespace != null))
                    {
                        resName = this._locationInfo.Namespace + Type.Delimiter + resourceFileName;
                    }
                    FrameworkEventSource.Log.ResourceManagerNeutralResourcesNotFound(this.BaseNameField, this.MainAssembly, resName);
                }
            }
            this.ResourceSets = new Hashtable();
        }
        protected static CultureInfo GetNeutralResourcesLanguage(Assembly a)
        {
            // This method should be obsolete - replace it with the one below.
            // Unfortunately, we made it protected.
            UltimateResourceFallbackLocation ignoringUsefulData = UltimateResourceFallbackLocation.MainAssembly;
            CultureInfo culture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(a, ref ignoringUsefulData);

            return(culture);
        }
Beispiel #4
0
        private void CommonAssemblyInit()
        {
            // Now we can use the managed resources even when using PRI's to support the APIs GetObject, GetStream...etc.
            _useManifest = true;

            _resourceSets          = new Dictionary <string, ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();

            ResourceManagerMediator mediator = new ResourceManagerMediator(this);

            _resourceGroveler = new ManifestBasedResourceGroveler(mediator);

            Debug.Assert(MainAssembly != null);
            _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, out _fallbackLoc);
        }
Beispiel #5
0
        // Trying to unify code as much as possible, even though having to do a
        // security check in each constructor prevents it.
        private void CommonAssemblyInit()
        {
#if FEATURE_APPX || ENABLE_WINRT
            SetUapConfiguration();
#endif

            // Now we can use the managed resources even when using PRI's to support the APIs GetObject, GetStream...etc.
            _useManifest = true;

            _resourceSets          = new Dictionary <string, ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();

            ResourceManagerMediator mediator = new ResourceManagerMediator(this);
            _resourceGroveler = new ManifestBasedResourceGroveler(mediator);

            _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, out _fallbackLoc);
        }
Beispiel #6
0
        internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, ref UltimateResourceFallbackLocation fallbackLocation)
        {
            string text = null;
            short  num  = 0;

            if (!ManifestBasedResourceGroveler.GetNeutralResourcesLanguageAttribute(((RuntimeAssembly)a).GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref text), out num))
            {
                if (FrameworkEventSource.IsInitialized)
                {
                    FrameworkEventSource.Log.ResourceManagerNeutralResourceAttributeMissing(a);
                }
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return(CultureInfo.InvariantCulture);
            }
            if (num < 0 || num > 1)
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", new object[]
                {
                    num
                }));
            }
            fallbackLocation = (UltimateResourceFallbackLocation)num;
            CultureInfo result;

            try
            {
                CultureInfo cultureInfo = CultureInfo.GetCultureInfo(text);
                result = cultureInfo;
            }
            catch (ArgumentException innerException)
            {
                if (!(a == typeof(object).Assembly))
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_Asm_Culture", new object[]
                    {
                        a.ToString(),
                        text
                    }), innerException);
                }
                result = CultureInfo.InvariantCulture;
            }
            return(result);
        }
        private void OnDeserialized(StreamingContext ctx)
        {
            this._resourceSets = new Dictionary <string, ResourceSet>();
            ResourceManagerMediator mediator = new ResourceManagerMediator(this);

            if (this.UseManifest)
            {
                this.resourceGroveler = new ManifestBasedResourceGroveler(mediator);
            }
            else
            {
                this.resourceGroveler = new FileBasedResourceGroveler(mediator);
            }
            if (this.m_callingAssembly == null)
            {
                this.m_callingAssembly = (RuntimeAssembly)this._callingAssembly;
            }
            if (this.UseManifest && (this._neutralResourcesCulture == null))
            {
                this._neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(this.MainAssembly, ref this._fallbackLoc);
            }
        }
Beispiel #8
0
 protected static CultureInfo GetNeutralResourcesLanguage(Assembly a)
 {
     // This method should be obsolete - replace it with the one below.
     // Unfortunately, we made it protected.
     return(ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(a, out _));
 }
        protected static CultureInfo GetNeutralResourcesLanguage(Assembly a)
        {
            UltimateResourceFallbackLocation mainAssembly = UltimateResourceFallbackLocation.MainAssembly;

            return(ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(a, ref mainAssembly));
        }