次の方法で共有


ResourceManager コンストラクタ (String, Assembly)

指定したルート名から派生したファイルに含まれているリソースを検索する ResourceManager クラスの新しいインスタンスを、指定した Assembly を使用して初期化します。

名前空間: System.Resources
アセンブリ: mscorlib (mscorlib.dll 内)

構文

'宣言
Public Sub New ( _
    baseName As String, _
    assembly As Assembly _
)
'使用
Dim baseName As String
Dim assembly As Assembly

Dim instance As New ResourceManager(baseName, assembly)
public ResourceManager (
    string baseName,
    Assembly assembly
)
public:
ResourceManager (
    String^ baseName, 
    Assembly^ assembly
)
public ResourceManager (
    String baseName, 
    Assembly assembly
)
public function ResourceManager (
    baseName : String, 
    assembly : Assembly
)

パラメータ

  • baseName
    リソースのルート名。たとえば、"MyResource.en-US.resources" というリソース ファイルのルート名は "MyResource" です。
  • assembly
    リソースのメイン Assembly

例外

例外の種類 条件

ArgumentNullException

baseName パラメータまたは assembly パラメータが null 参照 (Visual Basic では Nothing) です。

解説

それぞれのリソース ファイルは、サテライト アセンブリに含める必要があります。インバリアント カルチャの .resources ファイルはメイン アセンブリに含めます。サテライト アセンブリは、そのアセンブリのマニフェストで指定されている単一カルチャのリソースを含んでいるものと見なされ、必要に応じて読み込まれます。

このコンストラクタは、システム提供の ResourceSet 実装を使用します。カスタム リソース ファイル形式を使用するには、ResourceSet クラスから派生させ、GetDefaultReaderGetDefaultWriter をオーバーライドし、3 番目のパラメータとして Type をとるコンストラクタにその型を渡します。カスタム ResourceSet を使用すると、リソースのキャッシュ ポリシーの制御、または独自のリソース ファイル形式のサポートのために役立つことがありますが、通常は必要ありません。

使用例

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

Class ResourcesExample
   
    Public Shared Sub Main()
        ' Create a resource manager to retrieve resources.
        Dim rm As New ResourceManager("items", _
           [Assembly].GetExecutingAssembly())
       
        ' Get the culture of the currently executing thread.
        ' The value of ci will determine the culture of
        ' the resources that the resource manager retrieves.
        Dim ci As CultureInfo = Thread.CurrentThread.CurrentCulture
      
        ' Retrieve the value of the string resource named 
        ' "welcome" localized for the culture specified by ci.
        Dim str As [String] = rm.GetString("welcome", ci)
        Console.WriteLine(str)
    End Sub
End Class
using System;
using System.Globalization;
using System.Threading;
using System.Resources;
using System.Reflection;

class ResourcesExample 
{
    public static void Main() 
    {
       // Create a resource manager to retrieve resources.
       ResourceManager rm = new ResourceManager("items", 
          Assembly.GetExecutingAssembly());

       // Get the culture of the currently executing thread.
       // The value of ci will determine the culture of
       // the resources that the resource manager retrieves.
       CultureInfo ci = Thread.CurrentThread.CurrentCulture;
        
       // Retrieve the value of the string resource named 
       // "welcome", localized for the culture specified by ci.
       String str = rm.GetString("welcome", ci);
       Console.WriteLine(str);
    }
}
using namespace System;
using namespace System::Globalization;
using namespace System::Threading;
using namespace System::Resources;
using namespace System::Reflection;
int main()
{
   
   // Create a resource manager to retrieve resources.
   ResourceManager^ rm = gcnew ResourceManager( "items",Assembly::GetExecutingAssembly() );
   
   // Get the culture of the currently executing thread.
   // The value of ci will determine the culture of
   // the resources that the resource manager retrieves.
   CultureInfo^ ci = Thread::CurrentThread->CurrentCulture;
   
   // Retrieve the value of the string resource named
   // S"welcome", localized for the culture specified by ci.
   String^ str = rm->GetString( "welcome", ci );
   Console::WriteLine( str );
}
import System.*;
import System.Globalization.*;
import System.Threading.*;
import System.Resources.*;
import System.Reflection.*;

class ResourcesExample
{

    public static void main(String[] args)
    {
        // Create a resource manager to retrieve resources.
        ResourceManager rm = new ResourceManager("items", 
            Assembly.GetExecutingAssembly());

        // Get the culture of the currently executing thread.
        // The value of ci will determine the culture of
        // the resources that the resource manager retrieves.
        CultureInfo ci = 
            System.Threading.Thread.get_CurrentThread().get_CurrentCulture();

        // Retrieve the value of the string resource named 
        // "welcome", localized for the culture specified by ci.
        String str = rm.GetString("welcome", ci);
        Console.WriteLine(str);
    } //main
} //ResourcesExample

プラットフォーム

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

参照

関連項目

ResourceManager クラス
ResourceManager メンバ
System.Resources 名前空間