本文档已存档,并且将不进行维护。

NeutralResourcesLanguageAttribute 类

ResourceManager 通知程序集的非特定区域性。无法继承此类。

命名空间: System.Resources
程序集: mscorlib(在 mscorlib.dll 中)

[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple=false)] 
[ComVisibleAttribute(true)] 
public sealed class NeutralResourcesLanguageAttribute : Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class NeutralResourcesLanguageAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple=false) 
ComVisibleAttribute(true) 
public final class NeutralResourcesLanguageAttribute extends Attribute
不适用。

NeutralResourcesLanguageAttribute 通知用于编写程序集非特定区域性资源的语言的 ResourceManager,还可以通知通过资源后备进程检索非特定区域性资源时,要使用的程序集(主程序集或附属程序集)的 ResourceManager。如果要查找的资源的区域性与非特定资源语言相同,ResourceManager 将自动使用位于主程序集中的资源,而不会根据当前进程的当前用户界面区域性来搜索附属程序集。这将提高对您加载的第一个资源的查找性能,并且可以减少您的工作集。

说明注意:

将此属性应用于您的主程序集,并传递给它将用于您的主程序集的非特定语言的名称。或者,可以传递 UltimateResourceFallbackLocation 枚举的一个成员,以指示检索后备资源的位置。强烈建议使用此属性。

下面的示例说明如何使用 NeutralResourcesLanguageAttribute 类。

using System;
using System.Resources;
using System.Globalization;
using System.Threading;

[assembly: NeutralResourcesLanguageAttribute("de" , UltimateResourceFallbackLocation.Satellite)]

public class Demo
{
        public static void Main(string[] args) {
			
			// If a specific culture is passed in through the command line, use that -- otherwise
			// just use the current ui culture
		
			String strCulture = "";
			if (args.Length == 1) 
			{
				strCulture = args[0];
			}
		if (strCulture != "") 
		{
			try {
				Thread.CurrentThread.CurrentUICulture = new CultureInfo(strCulture);
			}
			catch (ArgumentException e){
				Console.WriteLine(e.Message, "Bad command-line argument");
			}
		}
		else
			Console.WriteLine("Current culture is: {0}", CultureInfo.CurrentUICulture.ToString());

		ResourceManager rm;

		try
		{
			rm = new ResourceManager("MyStrings", typeof(Demo).Assembly);
			NeutralResourcesLanguageAttribute attr = new NeutralResourcesLanguageAttribute("de", UltimateResourceFallbackLocation.Satellite);
			Console.WriteLine("Neutral language = " + rm.GetString("Language") + ", Fallback location = " + attr.Location.ToString() + ", Fallback culture = " + attr.CultureName.ToString());
			Console.WriteLine(rm.GetString("MSG"));

		}
		catch (MissingSatelliteAssemblyException e){
			Console.WriteLine(e.Message, "Unable to locate satellite Assembly");
		}



        }

}

import System.*;
import System.Resources.*;
import System.Globalization.*;
import System.Threading.*;

/** @assembly NeutralResourcesLanguageAttribute("de",
    UltimateResourceFallbackLocation.Satellite)
 */
public class Demo
{
    public static void main(String[] args)
    {
        // If a specific culture is passed in through the command line, use
        // that -- otherwise just use the current ui culture
        String strCulture = "";
        if (args.get_Length() == 1) {
            strCulture = args[0];
        }
        if (!(strCulture.Equals(""))) {
            try {
                System.Threading.Thread.get_CurrentThread().
                    set_CurrentUICulture(new CultureInfo(strCulture));
            }
            catch (ArgumentException e) {
                Console.WriteLine(e.get_Message(), "Bad command-line argument");
            }
        }
        else {
            Console.WriteLine("Current culture is: {0}",
                CultureInfo.get_CurrentUICulture().ToString());
        }
        ResourceManager rm;
        try {
            rm = new ResourceManager("MyStrings",
                Demo.class.ToType().get_Assembly());
            NeutralResourcesLanguageAttribute attr = 
                new NeutralResourcesLanguageAttribute("de",
                UltimateResourceFallbackLocation.Satellite);
            Console.WriteLine("Neutral language = " 
                + rm.GetString("Language") + ", Fallback location = " 
                + attr.get_Location().ToString() + ", Fallback culture = " 
                + attr.get_CultureName().ToString());
            Console.WriteLine(rm.GetString("MSG"));
        }
        catch (MissingSatelliteAssemblyException e) {
            Console.WriteLine(e.get_Message(),
                "Unable to locate satellite Assembly");
        }
    } //main
} //Demo

System.Object
   System.Attribute
    System.Resources.NeutralResourcesLanguageAttribute

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。

.NET Framework

受以下版本支持:3.0、2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

XNA Framework

受以下版本支持:1.0
显示: