ResourceReader コンストラクター

定義

ResourceReader クラスの新しいインスタンスを初期化します。

オーバーロード

名前 説明
ResourceReader(Stream)

指定したストリームの ResourceReader クラスの新しいインスタンスを初期化します。

ResourceReader(String)

指定した名前付きリソース ファイルの ResourceReader クラスの新しいインスタンスを初期化します。

注釈

Important

信頼されていないデータでこの型のインスタンスを使用することは、セキュリティ上のリスクです。 このオブジェクトは、信頼できるデータでのみ使用します。 詳細については、「すべての入力を検証する」を参照してください。

ResourceReader(Stream)

指定したストリームの ResourceReader クラスの新しいインスタンスを初期化します。

public:
 ResourceReader(System::IO::Stream ^ stream);
public ResourceReader(System.IO.Stream stream);
[System.Security.SecurityCritical]
public ResourceReader(System.IO.Stream stream);
new System.Resources.ResourceReader : System.IO.Stream -> System.Resources.ResourceReader
[<System.Security.SecurityCritical>]
new System.Resources.ResourceReader : System.IO.Stream -> System.Resources.ResourceReader
Public Sub New (stream As Stream)

パラメーター

stream
Stream

リソースを読み取るための入力ストリーム。

属性

例外

stream パラメーターは読み取りできません。

stream パラメーターはnull

streamへのアクセス中に I/O エラーが発生しました。

このセクションの例では、 PatientForm.txt という名前の次の .txt ファイルを使用して、アプリケーションで使用されるリソースを定義します。

Title="Top Pet Animal Clinic"
Label1="Patient Number:"
Label2="Pet Name:"
Label3="Species:"
Label4="Breed:"
Label5="Date of Birth:"
Label6="Age:"
Label7="Owner:"
Label8="Address:"
Label9="Home Phone:"
Label10="Work Phone:"
Label11="Mobile Phone:"

次のコマンドを実行して、.txt ファイルを .resources ファイルにコンパイルできます。

resgen PatientForm.txt

次の例では、リソース ファイルが、アプリケーションの実行可能コードを含むアセンブリに埋め込まれていることを前提としています。 現在実行中のアセンブリから PatientForm.resources という名前のリソース ファイルを取得し、各リソースの名前と値を表示します。

using System;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Resources;

public class Example
{
   public static void Main()
   {
      var assem = typeof(Example).Assembly;
      var fs = assem.GetManifestResourceStream("PatientForm.resources");
      var rr = new ResourceReader(fs);
      IDictionaryEnumerator dict = rr.GetEnumerator();
      int ctr = 0;

      while (dict.MoveNext()) {
         ctr++;
         Console.WriteLine("{0:00}: {1} = {2}", ctr, dict.Key, dict.Value);
      }
      rr.Close();
   }
}
// The example displays the following output:
//       01: Label3 = "Species:"
//       02: Label2 = "Pet Name:"
//       03: Label1 = "Patient Number:"
//       04: Label7 = "Owner:"
//       05: Label6 = "Age:"
//       06: Label5 = "Date of Birth:"
//       07: Label4 = "Breed:"
//       08: Label9 = "Home Phone:"
//       09: Label8 = "Address:"
//       10: Title = "Top Pet Animal Clinic"
//       11: Label10 = "Work Phone:"
//       12: Label11 = "Mobile Phone:"
Imports System.Collections
Imports System.IO
Imports System.Reflection
Imports System.Resources

Module Example
   Public Sub Main()
      Dim assem As Assembly = GetType(Example).Assembly
      Dim fs As Stream = assem.GetManifestResourceStream("PatientForm.resources")
      Dim rr As New ResourceReader(fs)
      Dim dict As IDictionaryEnumerator = rr.GetEnumerator
      Dim ctr As Integer

      Do While dict.MoveNext()
         ctr += 1
         Console.WriteLine("{0:00}: {1} = {2}", ctr, dict.Key, dict.Value)
      Loop

      rr.Close()
   End Sub
End Module
' The example displays the following output:
'       01: Label3 = "Species:"
'       02: Label2 = "Pet Name:"
'       03: Label1 = "Patient Number:"
'       04: Label7 = "Owner:"
'       05: Label6 = "Age:"
'       06: Label5 = "Date of Birth:"
'       07: Label4 = "Breed:"
'       08: Label9 = "Home Phone:"
'       09: Label8 = "Address:"
'       10: Title = "Top Pet Animal Clinic"
'       11: Label10 = "Work Phone:"
'       12: Label11 = "Mobile Phone:"

C# の例の名前が Example.cs の場合は、次のコマンドを使用してコンパイルできます。

csc Example.cs /res:PatientForm.resources

Visual Basicの例Example.vb という名前の場合は、次のコマンドを使用してコンパイルできます。

vbc Example.vb /res:PatientForm.resources

注釈

ResourceReader(Stream) コンストラクターは、スタンドアロンの .resources ファイルまたはアセンブリに埋め込まれている .resources ファイルからリソースを取得するResourceReader オブジェクトをインスタンス化します。 スタンドアロンの .resources ファイルから読み取るために、 Stream オブジェクトをインスタンス化し、 ResourceReader(Stream) コンストラクターに渡します。 埋め込み .resources ファイルから読み取るために、.resources ファイルの大文字と小文字を区別する名前を持つ Assembly.GetManifestResourceStream メソッドを呼び出し、返された Stream オブジェクトを ResourceReader(Stream) コンストラクターに渡します。

Important

信頼されていないデータでこの型のインスタンスを使用することは、セキュリティ上のリスクです。 このオブジェクトは、信頼できるデータでのみ使用します。 詳細については、「すべての入力を検証する」を参照してください。

こちらもご覧ください

適用対象

ResourceReader(String)

指定した名前付きリソース ファイルの ResourceReader クラスの新しいインスタンスを初期化します。

public:
 ResourceReader(System::String ^ fileName);
public ResourceReader(string fileName);
new System.Resources.ResourceReader : string -> System.Resources.ResourceReader
Public Sub New (fileName As String)

パラメーター

fileName
String

読み取るリソース ファイルのパスと名前。 filename では大文字と小文字は区別されません。

例外

fileName パラメーターはnull

ファイルが見つかりません。

I/O エラーが発生しました。

リソース ファイルの形式が無効です。 たとえば、ファイルの長さは 0 にすることができます。

このセクションの例では、 PatientForm.txt という名前の次の .txt ファイルを使用して、アプリケーションで使用されるリソースを定義します。

Title="Top Pet Animal Clinic"
Label1="Patient Number:"
Label2="Pet Name:"
Label3="Species:"
Label4="Breed:"
Label5="Date of Birth:"
Label6="Age:"
Label7="Owner:"
Label8="Address:"
Label9="Home Phone:"
Label10="Work Phone:"
Label11="Mobile Phone:"

この .txt ファイルを .resources ファイルにコンパイルするには、次のコマンドを実行します。

resgen PatientForm.txt

次の例では、 PatientForm.resources 内のリソースを列挙し、それぞれの名前と値を表示します。

using System;
using System.Collections;
using System.Resources;

public class Example
{
   public static void Main()
   {
      var rr = new ResourceReader("PatientForm.resources");
      IDictionaryEnumerator dict = rr.GetEnumerator();
      int ctr = 0;

      while (dict.MoveNext()) {
         ctr++;
         Console.WriteLine("{0:00}: {1} = {2}", ctr, dict.Key, dict.Value);
      }

      rr.Close();
   }
}
// The example displays the following output:
//       01: Label3 = "Species:"
//       02: Label2 = "Pet Name:"
//       03: Label1 = "Patient Number:"
//       04: Label7 = "Owner:"
//       05: Label6 = "Age:"
//       06: Label5 = "Date of Birth:"
//       07: Label4 = "Breed:"
//       08: Label9 = "Home Phone:"
//       09: Label8 = "Address:"
//       10: Title = "Top Pet Animal Clinic"
//       11: Label10 = "Work Phone:"
//       12: Label11 = "Mobile Phone:"
Imports System.Collections
Imports System.Resources

Module Example
   Public Sub Main()
      Dim rr As New ResourceReader("PatientForm.resources")
      Dim dict As IDictionaryEnumerator = rr.GetEnumerator
      Dim ctr As Integer

      Do While dict.MoveNext()
         ctr += 1
         Console.WriteLine("{0:00}: {1} = {2}", ctr, dict.Key, dict.Value)
      Loop
      
      rr.Close()
   End Sub
End Module
' The example displays the following output:
'       01: Label3 = "Species:"
'       02: Label2 = "Pet Name:"
'       03: Label1 = "Patient Number:"
'       04: Label7 = "Owner:"
'       05: Label6 = "Age:"
'       06: Label5 = "Date of Birth:"
'       07: Label4 = "Breed:"
'       08: Label9 = "Home Phone:"
'       09: Label8 = "Address:"
'       10: Title = "Top Pet Animal Clinic"
'       11: Label10 = "Work Phone:"
'       12: Label11 = "Mobile Phone:"

注釈

ResourceReader(String) コンストラクターは、スタンドアロンの .resources ファイルからリソースを取得するResourceReader オブジェクトをインスタンス化します。 埋め込み .resources ファイルからリソースを取得するには、 ResourceReader(Stream) コンストラクターを使用します。

Important

信頼されていないデータでこの型のインスタンスを使用することは、セキュリティ上のリスクです。 このオブジェクトは、信頼できるデータでのみ使用します。 詳細については、「すべての入力を検証する」を参照してください。

適用対象