ResourceReader Construtores

Definição

Inicializa uma nova instância da classe ResourceReader.Initializes a new instance of the ResourceReader class.

Sobrecargas

ResourceReader(Stream)

Inicializa uma nova instância da classe ResourceReader para o fluxo especificado.Initializes a new instance of the ResourceReader class for the specified stream.

ResourceReader(String)

Inicializa uma nova instância da classe ResourceReader para o arquivo de recurso nomeado especificado.Initializes a new instance of the ResourceReader class for the specified named resource file.

Comentários

> [!IMPORTANT] > Usar uma instância deste objeto quando você tiver dados não confiáveis é um risco à segurança.Using an instance of this object with untrusted data is a security risk. Use esse objeto somente quando você tiver dados confiáveis.Use this object only with trusted data. Para obter mais informações, confira Validação de dados.For more information, see Data Validation..> [!IMPORTANT] > Usar uma instância deste objeto quando você tiver dados não confiáveis é um risco à segurança.Using an instance of this object with untrusted data is a security risk. Use esse objeto somente quando você tiver dados confiáveis.Use this object only with trusted data. Para obter mais informações, confira Validação de dados.For more information, see Data Validation..

ResourceReader(Stream)

Inicializa uma nova instância da classe ResourceReader para o fluxo especificado.Initializes a new instance of the ResourceReader class for the specified stream.

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)

Parâmetros

stream
Stream

O fluxo de entrada para a leitura de recursos.The input stream for reading resources.

Atributos

Exceções

O parâmetro stream não é legível.The stream parameter is not readable.

O parâmetro stream é null.The stream parameter is null.

Erro de E/S ao acessar stream.An I/O error has occurred while accessing stream.

Exemplos

O exemplo nesta seção usa o seguinte arquivo. txt chamado PatientForm.txt para definir os recursos usados por um aplicativo.The example in this section uses the following .txt file named PatientForm.txt to define the resources used by an application.

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:"  

Você pode compilar o arquivo. txt em um arquivo. Resources emitindo o seguinte comando:You can compile the .txt file into a .resources file by issuing the following command:

ResGen PatientForm.txtresgen PatientForm.txt

O exemplo a seguir pressupõe que o arquivo de recurso seja inserido no assembly que contém o código executável do aplicativo.The following example assumes that the resource file is embedded in the assembly that contains the application's executable code. Ele recupera um arquivo de recurso chamado PatientForm.resources a partir dos assemblies em execução no momento e exibe o nome e o valor de cada um de seus recursos.It retrieves a resource file named PatientForm.resources from the currently executing assemblies and displays the name and value of each of its 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:"

Se o exemplo do C# for nomeado Example.cs , você poderá compilá-lo usando o seguinte comando:If the C# example is named Example.cs, you can compile it by using the following command:

Exemplo de CSC. cs/res: PatientForm. Resourcescsc Example.cs /res:PatientForm.resources

Se o exemplo de Visual Basic for nomeado Example.vb , você poderá compilá-lo usando o seguinte comando:If the Visual Basic example is named Example.vb, you can compile it by using the following command:

Exemplo de Vbc. vb/res: PatientForm. Resourcesvbc Example.vb /res:PatientForm.resources

Comentários

O ResourceReader(Stream) construtor instancia um ResourceReader objeto que recupera recursos de um arquivo. Resources autônomo ou de um arquivo. Resources que é inserido em um assembly.The ResourceReader(Stream) constructor instantiates a ResourceReader object that retrieves resources either from a standalone .resources file or from a .resources file that is embedded in an assembly. Para ler de um arquivo. Resources autônomo, crie uma instância de um Stream objeto e passe-o para o ResourceReader(Stream) Construtor.To read from a standalone .resources file, instantiate a Stream object and pass it to the ResourceReader(Stream) constructor. Para ler a partir de um arquivo. Resources inserido, chame o Assembly.GetManifestResourceStream método com o nome que diferencia maiúsculas de minúsculas do arquivo. Resources e passe o Stream objeto retornado para o ResourceReader(Stream) Construtor.To read from an embedded .resources file, call the Assembly.GetManifestResourceStream method with the case-sensitive name of the .resources file, and pass the returned Stream object to the ResourceReader(Stream) constructor.

Importante

Usar uma instância deste objeto quando você tiver dados não confiáveis é um risco à segurança.Using an instance of this object with untrusted data is a security risk. Use esse objeto somente quando você tiver dados confiáveis.Use this object only with trusted data. Para obter mais informações, confira Validação de dados.For more information, see Data Validation.

Confira também

Aplica-se a

ResourceReader(String)

Inicializa uma nova instância da classe ResourceReader para o arquivo de recurso nomeado especificado.Initializes a new instance of the ResourceReader class for the specified named resource file.

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

Parâmetros

fileName
String

O caminho e o nome do arquivo de recurso a ser lido.The path and name of the resource file to read. O nome do arquivo não diferencia maiúsculas de minúsculas.filename is not case-sensitive.

Exceções

O parâmetro fileName é null.The fileName parameter is null.

Não é possível encontrar o arquivo.The file cannot be found.

Ocorreu um erro de E/S.An I/O error has occurred.

O arquivo de recurso tem um formato inválido.The resource file has an invalid format. Por exemplo, o tamanho do arquivo pode ser zero.For example, the length of the file may be zero.

Exemplos

O exemplo nesta seção usa o seguinte arquivo. txt chamado PatientForm.txt para definir os recursos usados por um aplicativo.The example in this section uses the following .txt file named PatientForm.txt to define the resources used by an application.

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:"  

Você pode compilar esse arquivo. txt em um arquivo. Resources emitindo o seguinte comando:You can compile this .txt file into a .resources file by issuing the following command:

ResGen PatientForm.txtresgen PatientForm.txt

O exemplo a seguir enumera os recursos no PatientForm.resources e exibe o nome e o valor de cada um.The following example enumerates the resources in PatientForm.resources and displays the name and value of each.

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:"

Comentários

O ResourceReader(String) construtor instancia um ResourceReader objeto que recupera recursos de um arquivo. Resources autônomo.The ResourceReader(String) constructor instantiates a ResourceReader object that retrieves resources from a standalone .resources file. Para recuperar recursos de um arquivo. Resources inserido, use o ResourceReader(Stream) Construtor.To retrieve resources from an embedded .resources file, use the ResourceReader(Stream) constructor.

Importante

Usar uma instância deste objeto quando você tiver dados não confiáveis é um risco à segurança.Using an instance of this object with untrusted data is a security risk. Use esse objeto somente quando você tiver dados confiáveis.Use this object only with trusted data. Para obter mais informações, confira Validação de dados.For more information, see Data Validation.

Aplica-se a