示例#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();
        }
        public NeutralResourcesLanguageAttribute(String cultureName)
        {
            if (cultureName == null)
                throw new ArgumentNullException("cultureName");

            _culture = cultureName;
            _fallbackLoc = UltimateResourceFallbackLocation.MainAssembly;
        }
示例#4
0
 public NeutralResourcesLanguageAttribute(string cultureName)
 {
     if (cultureName == null)
     {
         throw new ArgumentNullException("cultureName");
     }
     this._culture     = cultureName;
     this._fallbackLoc = UltimateResourceFallbackLocation.MainAssembly;
 }
 /// <summary>Initializes a new instance of the <see cref="T:System.Resources.NeutralResourcesLanguageAttribute" /> class with the specified ultimate resource fallback location.</summary>
 /// <param name="cultureName">The name of the culture that the current assembly's neutral resources were written in.</param>
 /// <param name="location">An <see cref="T:System.Resources.UltimateResourceFallbackLocation" /> enumeration value indicating the location from which to retrieve neutral fallback resources.</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="cultureName" /> is null.</exception>
 /// <exception cref="T:System.ArgumentException">
 ///   <paramref name="location" /> is not a member of <see cref="T:System.Resources.UltimateResourceFallbackLocation" />.</exception>
 public NeutralResourcesLanguageAttribute(string cultureName, UltimateResourceFallbackLocation location)
 {
     if (cultureName == null)
     {
         throw new ArgumentNullException("culture is null");
     }
     this.culture = cultureName;
     this.loc     = location;
 }
示例#6
0
        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);
        }
		public NeutralResourcesLanguageAttribute (string cultureName, UltimateResourceFallbackLocation location)
		{
			if(cultureName==null) {
				throw new ArgumentNullException("culture is null");
			}
			
			culture = cultureName;
			loc = location;
		}
示例#8
0
        internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, ref UltimateResourceFallbackLocation fallbackLocation)
        {
#if FEATURE_LEGACYNETCF
            // Windows Phone 7.0/7.1 ignore NeutralResourceLanguage attribute and
            // defaults fallbackLocation to MainAssembly
            if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
            {
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return(CultureInfo.InvariantCulture);
            }
#endif

            Contract.Assert(a != null, "assembly != null");
            string cultureName = null;
            short  fallback    = 0;
            if (GetNeutralResourcesLanguageAttribute(((RuntimeAssembly)a).GetNativeHandle(),
                                                     JitHelpers.GetStringHandleOnStack(ref cultureName),
                                                     out fallback))
            {
                if ((UltimateResourceFallbackLocation)fallback < UltimateResourceFallbackLocation.MainAssembly || (UltimateResourceFallbackLocation)fallback > UltimateResourceFallbackLocation.Satellite)
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", fallback));
                }
                fallbackLocation = (UltimateResourceFallbackLocation)fallback;
            }
            else
            {
#if !FEATURE_CORECLR
                if (FrameworkEventSource.IsInitialized)
                {
                    FrameworkEventSource.Log.ResourceManagerNeutralResourceAttributeMissing(a);
                }
#endif
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return(CultureInfo.InvariantCulture);
            }

            try
            {
                CultureInfo c = CultureInfo.GetCultureInfo(cultureName);
                return(c);
            }
            catch (ArgumentException e)
            { // we should catch ArgumentException only.
                // Note we could go into infinite loops if mscorlib's
                // NeutralResourcesLanguageAttribute is mangled.  If this assert
                // fires, please fix the build process for the BCL directory.
                if (a == typeof(Object).Assembly)
                {
                    Contract.Assert(false, "mscorlib's NeutralResourcesLanguageAttribute is a malformed culture name! name: \"" + cultureName + "\"  Exception: " + e);
                    return(CultureInfo.InvariantCulture);
                }

                throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_Asm_Culture", a.ToString(), cultureName), e);
            }
        }
        public NeutralResourcesLanguageAttribute(String cultureName, UltimateResourceFallbackLocation location)
        {
            if (cultureName == null)
                throw new ArgumentNullException("cultureName");
            if (!Enum.IsDefined(typeof(UltimateResourceFallbackLocation), location))
                throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", location));

            _culture = cultureName;
            _fallbackLoc = location;
        }
        public NeutralResourcesLanguageAttribute(String cultureName)
        {
            if (cultureName == null)
            {
                throw new ArgumentNullException(nameof(cultureName));
            }
            Contract.EndContractBlock();

            _culture     = cultureName;
            _fallbackLoc = UltimateResourceFallbackLocation.MainAssembly;
        }
示例#11
0
        public NeutralResourcesLanguageAttribute(string cultureName, UltimateResourceFallbackLocation location)
        {
            ArgumentNullException.ThrowIfNull(cultureName);

            if (!Enum.IsDefined(typeof(UltimateResourceFallbackLocation), location))
            {
                throw new ArgumentException(SR.Format(SR.Arg_InvalidNeutralResourcesLanguage_FallbackLoc, location));
            }

            CultureName = cultureName;
            Location    = location;
        }
示例#12
0
        internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, ref UltimateResourceFallbackLocation fallbackLocation)
        {
            IList <CustomAttributeData> customAttributes = CustomAttributeData.GetCustomAttributes(a);
            CustomAttributeData         data             = null;

            for (int i = 0; i < customAttributes.Count; i++)
            {
                if (customAttributes[i].Constructor.DeclaringType == typeof(NeutralResourcesLanguageAttribute))
                {
                    data = customAttributes[i];
                    break;
                }
            }
            if (data == null)
            {
                if (FrameworkEventSource.IsInitialized)
                {
                    FrameworkEventSource.Log.ResourceManagerNeutralResourceAttributeMissing(a);
                }
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return(CultureInfo.InvariantCulture);
            }
            string name = null;

            if (data.Constructor.GetParameters().Length == 2)
            {
                CustomAttributeTypedArgument argument = data.ConstructorArguments[1];
                fallbackLocation = (UltimateResourceFallbackLocation)argument.Value;
                if ((fallbackLocation < UltimateResourceFallbackLocation.MainAssembly) || (fallbackLocation > UltimateResourceFallbackLocation.Satellite))
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", new object[] { (UltimateResourceFallbackLocation)fallbackLocation }));
                }
            }
            else
            {
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
            }
            CustomAttributeTypedArgument argument2 = data.ConstructorArguments[0];

            name = argument2.Value as string;
            try
            {
                return(CultureInfo.GetCultureInfo(name));
            }
            catch (ArgumentException exception)
            {
                if (a != typeof(object).Assembly)
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_Asm_Culture", new object[] { a.ToString(), name }), exception);
                }
                return(CultureInfo.InvariantCulture);
            }
        }
示例#13
0
 public NeutralResourcesLanguageAttribute(string cultureName, UltimateResourceFallbackLocation location)
 {
     if (cultureName == null)
     {
         throw new ArgumentNullException("cultureName");
     }
     if (!Enum.IsDefined(typeof(UltimateResourceFallbackLocation), location))
     {
         throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", new object[] { location }));
     }
     this._culture     = cultureName;
     this._fallbackLoc = location;
 }
示例#14
0
        public NeutralResourcesLanguageAttribute(String cultureName, UltimateResourceFallbackLocation location)
        {
            if (cultureName == null)
            {
                throw new ArgumentNullException(nameof(cultureName));
            }
            if (!Enum.IsDefined(typeof(UltimateResourceFallbackLocation), location))
            {
                throw new ArgumentException(SR.Format(SR.Arg_InvalidNeutralResourcesLanguage_FallbackLoc, location));
            }

            _culture     = cultureName;
            _fallbackLoc = location;
        }
        public NeutralResourcesLanguageAttribute(String cultureName, UltimateResourceFallbackLocation location)
        {
            if (cultureName == null)
            {
                throw new ArgumentNullException(nameof(cultureName));
            }
            if (!Enum.IsDefined(typeof(UltimateResourceFallbackLocation), location))
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", location));
            }
            Contract.EndContractBlock();

            _culture     = cultureName;
            _fallbackLoc = location;
        }
示例#16
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()
        {
            // 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();

            _fallbackLoc = UltimateResourceFallbackLocation.MainAssembly;

            ResourceManagerMediator mediator = new ResourceManagerMediator(this);

            resourceGroveler = new ManifestBasedResourceGroveler(mediator);

            _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, ref _fallbackLoc);
        }
示例#17
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);
        }
        internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, ref UltimateResourceFallbackLocation fallbackLocation)
        {
            Debug.Assert(a != null, "assembly != null");
            string cultureName = null;
            short  fallback    = 0;

            if (GetNeutralResourcesLanguageAttribute(((RuntimeAssembly)a).GetNativeHandle(),
                                                     JitHelpers.GetStringHandleOnStack(ref cultureName),
                                                     out fallback))
            {
                if ((UltimateResourceFallbackLocation)fallback < UltimateResourceFallbackLocation.MainAssembly || (UltimateResourceFallbackLocation)fallback > UltimateResourceFallbackLocation.Satellite)
                {
                    throw new ArgumentException(SR.Format(SR.Arg_InvalidNeutralResourcesLanguage_FallbackLoc, fallback));
                }
                fallbackLocation = (UltimateResourceFallbackLocation)fallback;
            }
            else
            {
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return(CultureInfo.InvariantCulture);
            }

            try
            {
                CultureInfo c = CultureInfo.GetCultureInfo(cultureName);
                return(c);
            }
            catch (ArgumentException e)
            { // we should catch ArgumentException only.
                // Note we could go into infinite loops if mscorlib's
                // NeutralResourcesLanguageAttribute is mangled.  If this assert
                // fires, please fix the build process for the BCL directory.
                if (a == typeof(object).Assembly)
                {
                    Debug.Fail(System.CoreLib.Name + "'s NeutralResourcesLanguageAttribute is a malformed culture name! name: \"" + cultureName + "\"  Exception: " + e);
                    return(CultureInfo.InvariantCulture);
                }

                throw new ArgumentException(SR.Format(SR.Arg_InvalidNeutralResourcesLanguage_Asm_Culture, a.ToString(), cultureName), e);
            }
        }
        internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, out UltimateResourceFallbackLocation fallbackLocation)
        {
            Debug.Assert(a != null, "assembly != null");

            var attr = a.GetCustomAttribute <NeutralResourcesLanguageAttribute>();

            if (attr == null)
            {
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return(CultureInfo.InvariantCulture);
            }

            fallbackLocation = attr.Location;
            if (fallbackLocation < UltimateResourceFallbackLocation.MainAssembly || fallbackLocation > UltimateResourceFallbackLocation.Satellite)
            {
                throw new ArgumentException(SR.Format(SR.Arg_InvalidNeutralResourcesLanguage_FallbackLoc, fallbackLocation));
            }

            try
            {
                return(CultureInfo.GetCultureInfo(attr.CultureName));
            }
            catch (ArgumentException e)
            { // we should catch ArgumentException only.
                // Note we could go into infinite loops if mscorlib's
                // NeutralResourcesLanguageAttribute is mangled.  If this assert
                // fires, please fix the build process for the BCL directory.
                if (a == typeof(object).Assembly)
                {
                    Debug.Fail(System.CoreLib.Name + "'s NeutralResourcesLanguageAttribute is a malformed culture name! name: \"" + attr.CultureName + "\"  Exception: " + e);
                    return(CultureInfo.InvariantCulture);
                }

                throw new ArgumentException(SR.Format(SR.Arg_InvalidNeutralResourcesLanguage_Asm_Culture, a, attr.CultureName), e);
            }
        }
 /// <summary>Initializes a new instance of the <see cref="T:System.Resources.NeutralResourcesLanguageAttribute" /> class with the specified ultimate resource fallback location.</summary><param name="cultureName">The name of the culture that the current assembly's neutral resources were written in.</param><param name="location">One of the enumeration values that indicates the location from which to retrieve neutral fallback resources.</param><exception cref="T:System.ArgumentNullException"><paramref name="cultureName" /> is null.</exception><exception cref="T:System.ArgumentException"><paramref name="location" /> is not a member of <see cref="T:System.Resources.UltimateResourceFallbackLocation" />.</exception>
 public NeutralResourcesLanguageAttribute(string cultureName, UltimateResourceFallbackLocation location)
 {
     throw new NotImplementedException();
 }
 public NeutralResourcesLanguageAttribute(string cultureName, UltimateResourceFallbackLocation location)
 {
 }
        // Trying to unify code as much as possible, even though having to do a
        // security check in each constructor prevents it.
        private void CommonSatelliteAssemblyInit()
        {
            UseManifest = true;
            UseSatelliteAssem = true;
    
            ResourceSets = new Hashtable();

            _fallbackLoc = UltimateResourceFallbackLocation.MainAssembly;

#if _DEBUG
            if (DEBUG >= 3) {
                // Detect missing neutral locale resources.
                String defaultResName = GetResourceFileName(CultureInfo.InvariantCulture);
                String outputResName = defaultResName;
                if (_locationInfo != null && _locationInfo.Namespace != null)
                    outputResName = _locationInfo.Namespace + Type.Delimiter + defaultResName;
                if (!MainAssemblyContainsResourceBlob(defaultResName)) {
                    BCLDebug.Log("Your main assembly really should contain the neutral culture's resources.  Expected to find a resource blob in your assembly manifest called \""+outputResName+"\".  Check capitalization in your assembly manifest.  If you're extremely careful though, this is only optional, not a requirement.");
                }
                else {
                    BCLDebug.Log("ResourceManager found default culture's " + ResFileExtension + " file, "+defaultResName);
                }
            }
#endif
        }
        private static CultureInfo GetNeutralResourcesLanguage(Assembly a, ref UltimateResourceFallbackLocation fallbackLocation)
        {
            BCLDebug.Assert(a != null, "assembly != null");

            IList<CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes(a);
            CustomAttributeData attr = null;
            for (int i = 0; i < attrs.Count; i++)
            {
                if (attrs[i].Constructor.DeclaringType == typeof(NeutralResourcesLanguageAttribute))
                {
                    attr = attrs[i];
                    break;
                }
            }

            if (attr == null)
            {
#if _DEBUG
                if (DEBUG >= 4) 
                    BCLDebug.Log("Consider putting the NeutralResourcesLanguageAttribute on assembly "+a.FullName);
#endif
                BCLDebug.Perf(false, "Consider adding NeutralResourcesLanguageAttribute to assembly "+a.FullName);
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return CultureInfo.InvariantCulture;
            }

            string cultureName = null;
            if (attr.Constructor.GetParameters().Length == 2) { 
                fallbackLocation = (UltimateResourceFallbackLocation)attr.ConstructorArguments[1].Value;
                if (fallbackLocation < UltimateResourceFallbackLocation.MainAssembly || fallbackLocation > UltimateResourceFallbackLocation.Satellite)
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", fallbackLocation));
            }
            else
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;

            cultureName = attr.ConstructorArguments[0].Value as string;

            try {
                CultureInfo c = CultureInfo.GetCultureInfo(cultureName);
                return c;
            }
            catch (ArgumentException e) { // we should catch ArgumentException only.
                // Note we could go into infinite loops if mscorlib's 
                // NeutralResourcesLanguageAttribute is mangled.  If this assert
                // fires, please fix the build process for the BCL directory.
                if (a == typeof(Object).Assembly) {
                    BCLDebug.Assert(false, "mscorlib's NeutralResourcesLanguageAttribute is a malformed culture name! name: \"" + cultureName + "\"  Exception: " + e);
                    return CultureInfo.InvariantCulture;
                }
                
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_Asm_Culture"), a.ToString(), cultureName), e);
            }
        }
 public NeutralResourcesLanguageAttribute(string cultureName, UltimateResourceFallbackLocation location)
 {
 }
 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)
        {
            UltimateResourceFallbackLocation mainAssembly = UltimateResourceFallbackLocation.MainAssembly;

            return(ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(a, ref mainAssembly));
        }
 internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, ref UltimateResourceFallbackLocation fallbackLocation)
 {
     IList<CustomAttributeData> customAttributes = CustomAttributeData.GetCustomAttributes(a);
     CustomAttributeData data = null;
     for (int i = 0; i < customAttributes.Count; i++)
     {
         if (customAttributes[i].Constructor.DeclaringType == typeof(NeutralResourcesLanguageAttribute))
         {
             data = customAttributes[i];
             break;
         }
     }
     if (data == null)
     {
         if (FrameworkEventSource.IsInitialized)
         {
             FrameworkEventSource.Log.ResourceManagerNeutralResourceAttributeMissing(a);
         }
         fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
         return CultureInfo.InvariantCulture;
     }
     string name = null;
     if (data.Constructor.GetParameters().Length == 2)
     {
         CustomAttributeTypedArgument argument = data.ConstructorArguments[1];
         fallbackLocation = (UltimateResourceFallbackLocation) argument.Value;
         if ((fallbackLocation < UltimateResourceFallbackLocation.MainAssembly) || (fallbackLocation > UltimateResourceFallbackLocation.Satellite))
         {
             throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", new object[] { (UltimateResourceFallbackLocation) fallbackLocation }));
         }
     }
     else
     {
         fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
     }
     CustomAttributeTypedArgument argument2 = data.ConstructorArguments[0];
     name = argument2.Value as string;
     try
     {
         return CultureInfo.GetCultureInfo(name);
     }
     catch (ArgumentException exception)
     {
         if (a != typeof(object).Assembly)
         {
             throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_Asm_Culture", new object[] { a.ToString(), name }), exception);
         }
         return CultureInfo.InvariantCulture;
     }
 }
        internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, ref UltimateResourceFallbackLocation fallbackLocation)
        {
            Debug.Assert(a != null, "assembly != null");
            string cultureName = null;
            short fallback = 0;
            if (GetNeutralResourcesLanguageAttribute(((RuntimeAssembly)a).GetNativeHandle(), 
                                                        JitHelpers.GetStringHandleOnStack(ref cultureName), 
                                                        out fallback)) {
                if ((UltimateResourceFallbackLocation)fallback < UltimateResourceFallbackLocation.MainAssembly || (UltimateResourceFallbackLocation)fallback > UltimateResourceFallbackLocation.Satellite) {
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", fallback));
                }
                fallbackLocation = (UltimateResourceFallbackLocation)fallback;
            }
            else {
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return CultureInfo.InvariantCulture;
            }

            try
            {
                CultureInfo c = CultureInfo.GetCultureInfo(cultureName);
                return c;
            }
            catch (ArgumentException e)
            { // we should catch ArgumentException only.
                // Note we could go into infinite loops if mscorlib's 
                // NeutralResourcesLanguageAttribute is mangled.  If this assert
                // fires, please fix the build process for the BCL directory.
                if (a == typeof(Object).Assembly)
                {
                    Debug.Assert(false, System.CoreLib.Name+"'s NeutralResourcesLanguageAttribute is a malformed culture name! name: \"" + cultureName + "\"  Exception: " + e);
                    return CultureInfo.InvariantCulture;
                }

                throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_Asm_Culture", a.ToString(), cultureName), e);
            }
        }
        internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, ref UltimateResourceFallbackLocation fallbackLocation)
        {

#if FEATURE_LEGACYNETCF
            // Windows Phone 7.0/7.1 ignore NeutralResourceLanguage attribute and 
            // defaults fallbackLocation to MainAssembly
            if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
            {
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return CultureInfo.InvariantCulture;
            }
#endif

            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));
                }
                fallbackLocation = (UltimateResourceFallbackLocation)fallback;
            }
            else {
#if !FEATURE_CORECLR && !MONO
                if (FrameworkEventSource.IsInitialized) {
                    FrameworkEventSource.Log.ResourceManagerNeutralResourceAttributeMissing(a);
                }
#endif
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return CultureInfo.InvariantCulture;
            }

            try
            {
                CultureInfo c = CultureInfo.GetCultureInfo(cultureName);
                return c;
            }
            catch (ArgumentException e)
            { // we should catch ArgumentException only.
                // Note we could go into infinite loops if mscorlib's 
                // NeutralResourcesLanguageAttribute is mangled.  If this assert
                // fires, please fix the build process for the BCL directory.
                if (a == typeof(Object).Assembly)
                {
                    Contract.Assert(false, "mscorlib's NeutralResourcesLanguageAttribute is a malformed culture name! name: \"" + cultureName + "\"  Exception: " + e);
                    return CultureInfo.InvariantCulture;
                }

                throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_Asm_Culture", a.ToString(), cultureName), e);
            }
        }

        // Constructs a new ResourceSet for a given file name.  The logic in
        // here avoids a ReflectionPermission check for our RuntimeResourceSet
        // for perf and working set reasons.
        // Use the assembly to resolve assembly manifest resource references.
        // Note that is can be null, but probably shouldn't be.
        // This method could use some refactoring. One thing at a time.
        [System.Security.SecurityCritical]
        internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, ref UltimateResourceFallbackLocation fallbackLocation)
        {

#if FEATURE_LEGACYNETCF
            // Windows Phone 7.0/7.1 ignore NeutralResourceLanguage attribute and 
            // defaults fallbackLocation to MainAssembly
            if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
            {
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return CultureInfo.InvariantCulture;
            }
#endif

            Contract.Assert(a != null, "assembly != null");
            string cultureName = null;
            short fallback = 0;
            if (GetNeutralResourcesLanguageAttribute(((RuntimeAssembly)a).GetNativeHandle(), 
                                                        JitHelpers.GetStringHandleOnStack(ref cultureName), 
                                                        out fallback)) {
                if ((UltimateResourceFallbackLocation)fallback < UltimateResourceFallbackLocation.MainAssembly || (UltimateResourceFallbackLocation)fallback > UltimateResourceFallbackLocation.Satellite) {
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", fallback));
                }
                fallbackLocation = (UltimateResourceFallbackLocation)fallback;
            }
            else {
#if !FEATURE_CORECLR
                if (FrameworkEventSource.IsInitialized) {
                    FrameworkEventSource.Log.ResourceManagerNeutralResourceAttributeMissing(a);
                }
#endif
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
                return CultureInfo.InvariantCulture;
            }

            try
            {
                CultureInfo c = CultureInfo.GetCultureInfo(cultureName);
                return c;
            }
            catch (ArgumentException e)
            { // we should catch ArgumentException only.
                // Note we could go into infinite loops if mscorlib's 
                // NeutralResourcesLanguageAttribute is mangled.  If this assert
                // fires, please fix the build process for the BCL directory.
                if (a == typeof(Object).Assembly)
                {
                    Contract.Assert(false, "mscorlib's NeutralResourcesLanguageAttribute is a malformed culture name! name: \"" + cultureName + "\"  Exception: " + e);
                    return CultureInfo.InvariantCulture;
                }

                throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_Asm_Culture", a.ToString(), cultureName), e);
            }
        }
        internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, ref UltimateResourceFallbackLocation fallbackLocation) 
        {
            Contract.Assert(a != null, "assembly != null"); 

            IList<CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes(a);
            CustomAttributeData attr = null;
            for (int i = 0; i < attrs.Count; i++) 
            {
                if (attrs[i].Constructor.DeclaringType == typeof(NeutralResourcesLanguageAttribute)) 
                { 
                    attr = attrs[i];
                    break; 
                }
            }

            if (attr == null) 
            {
#if !FEATURE_CORECLR 
                if (FrameworkEventSource.IsInitialized) 
                {
                    FrameworkEventSource.Log.ResourceManagerNeutralResourceAttributeMissing(a); 
                }
#endif

                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly; 
                return CultureInfo.InvariantCulture;
            } 
 
            string cultureName = null;
            if (attr.Constructor.GetParameters().Length == 2) 
            {
                fallbackLocation = (UltimateResourceFallbackLocation)attr.ConstructorArguments[1].Value;
                if (fallbackLocation < UltimateResourceFallbackLocation.MainAssembly || fallbackLocation > UltimateResourceFallbackLocation.Satellite)
                    throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", fallbackLocation)); 
            }
            else 
                fallbackLocation = UltimateResourceFallbackLocation.MainAssembly; 

            cultureName = attr.ConstructorArguments[0].Value as string; 

            try
            {
                CultureInfo c = CultureInfo.GetCultureInfo(cultureName); 
                return c;
            } 
            catch (ArgumentException e) 
            { // we should catch ArgumentException only.
                // Note we could go into infinite loops if mscorlib's 
                // NeutralResourcesLanguageAttribute is mangled.  If this assert
                // fires, please fix the build process for the BCL directory.
                if (a == typeof(Object).Assembly)
                { 
                    Contract.Assert(false, "mscorlib's NeutralResourcesLanguageAttribute is a malformed culture name! name: \"" + cultureName + "\"  Exception: " + e);
                    return CultureInfo.InvariantCulture; 
                } 

                throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_Asm_Culture", a.ToString(), cultureName), e); 
            }
        }
示例#32
0
        private void CommonAssemblyInit()
        {
            if (_bUsingModernResourceManagement == false)
            {
                UseManifest = true;
        
                _resourceSets = new Dictionary<String,ResourceSet>();
                _lastUsedResourceCache = new CultureNameResourceSetPair();

                _fallbackLoc = UltimateResourceFallbackLocation.MainAssembly;

                ResourceManagerMediator mediator = new ResourceManagerMediator(this);
                resourceGroveler = new ManifestBasedResourceGroveler(mediator);
            }

            _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, ref _fallbackLoc);

#if !FEATURE_CORECLR   // PAL doesn't support eventing, and we don't compile event providers for coreclr
            if (_bUsingModernResourceManagement == false)
            {
                if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled()) {
                    CultureInfo culture = CultureInfo.InvariantCulture;
                    String defaultResName = GetResourceFileName(culture);

                    if (resourceGroveler.HasNeutralResources(culture, defaultResName)) {
                        FrameworkEventSource.Log.ResourceManagerNeutralResourcesFound(BaseNameField, MainAssembly, defaultResName);
                    }
                    else {
                        String outputResName = defaultResName;
                        if (_locationInfo != null && _locationInfo.Namespace != null)
                            outputResName = _locationInfo.Namespace + Type.Delimiter + defaultResName;
                        FrameworkEventSource.Log.ResourceManagerNeutralResourcesNotFound(BaseNameField, MainAssembly, outputResName);
                    }
                }

#pragma warning disable 618
                ResourceSets = new Hashtable(); // for backward compatibility
#pragma warning restore 618
            }
#endif
        }
示例#33
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 (_bUsingModernResourceManagement == false)
            {
                UseManifest = true;
        
                _resourceSets = new Dictionary<String,ResourceSet>();
                _lastUsedResourceCache = new CultureNameResourceSetPair();

                _fallbackLoc = UltimateResourceFallbackLocation.MainAssembly;

                ResourceManagerMediator mediator = new ResourceManagerMediator(this);
                resourceGroveler = new ManifestBasedResourceGroveler(mediator);
            }

            _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, ref _fallbackLoc);
        }