NeutralResourcesLanguageAttribute 类

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

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

语法

声明
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple:=False)> _
Public NotInheritable Class NeutralResourcesLanguageAttribute
    Inherits Attribute
用法
Dim instance As NeutralResourcesLanguageAttribute
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple=false)] 
public sealed class NeutralResourcesLanguageAttribute : Attribute
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets::Assembly, AllowMultiple=false)] 
public ref class NeutralResourcesLanguageAttribute sealed : public Attribute
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple=false) */ 
public final class NeutralResourcesLanguageAttribute extends Attribute
ComVisibleAttribute(true) 
AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple=false) 
public final class NeutralResourcesLanguageAttribute extends Attribute

备注

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

提示

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

示例

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

Imports System
Imports System.Resources
Imports System.Globalization
Imports System.Threading



<assembly: NeutralResourcesLanguageAttribute("de", UltimateResourceFallbackLocation.Satellite)>
 

Public Class Demo
   
    Public Overloads Shared Sub Main(ByVal args() As String)

        ' If a specific culture is passed in through the command line, use that -- otherwise
        ' just use the current ui culture
        Dim strCulture As String = ""
        If args.Length = 1 Then
            strCulture = args(0)
        End If
        If strCulture <> "" Then
            Try
                Thread.CurrentThread.CurrentUICulture = New CultureInfo(strCulture)
            Catch e As ArgumentException
                Console.WriteLine(e.Message, "Bad command-line argument")
            End Try
        Else
            Console.WriteLine("Current culture is: {0}", CultureInfo.CurrentUICulture.ToString())
        End If
        Dim rm As ResourceManager

        Try
            rm = New ResourceManager("MyStrings", GetType(Demo).Assembly)
            Dim attr As 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 e As MissingSatelliteAssemblyException
            Console.WriteLine(e.Message, "Unable to locate satellite Assembly")
        End Try
    End Sub 'Main 
End Class 'Demo 

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");
        }



        }

}
using namespace System;
using namespace System::Resources;
using namespace System::Globalization;
using namespace System::Threading;

[assembly:NeutralResourcesLanguageAttribute("de",UltimateResourceFallbackLocation::Satellite)];
public ref class Demo
{
public:
   int FallbackDemo()
   {
      array<String^>^args = Environment::GetCommandLineArgs();
      
      // If a specific culture is passed in through the command line, use that -- otherwise
      // just use the current ui culture
      String^ strCulture = L"";
      if ( args->Length == 1 )
      {
         strCulture = args[ 0 ];
      }

      if (  !strCulture->Equals( L"" ) )
      {
         try
         {
            Thread::CurrentThread->CurrentUICulture = gcnew CultureInfo( strCulture );
         }
         catch ( ArgumentException^ e ) 
         {
            Console::WriteLine( e->Message, L"Bad command-line argument" );
         }

      }
      else
            Console::WriteLine( L"Current culture is: {0}", CultureInfo::CurrentUICulture );

      ResourceManager^ rm;
      try
      {
         
         rm = gcnew ResourceManager( L"MyStrings",Demo::typeid->Assembly );
         NeutralResourcesLanguageAttribute^ attr = gcnew NeutralResourcesLanguageAttribute( L"de",UltimateResourceFallbackLocation::Satellite );
         
         Console::WriteLine( L"Neutral language = {0}, Fallback location = {1}, Fallback culture = {2}", rm->GetString( L"Language" ), attr->Location, attr->CultureName );
         Console::WriteLine( rm->GetString( L"MSG" ) );
      }
      catch ( MissingSatelliteAssemblyException^ e ) 
      {
         Console::WriteLine( e->Message, L"Unable to locate satellite Assembly" );
      }

      return 1;
   }

};

void main()
{
   Demo^ d = gcnew Demo;
   d->FallbackDemo();
}
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 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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

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

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

NeutralResourcesLanguageAttribute 成员
System.Resources 命名空间
UltimateResourceFallbackLocation
FallbackLocation

其他资源

打包和部署资源