ResXResourceWriter.AddResource Método

Definição

Adiciona um recurso à lista de recursos a serem gravados.Adds a resource to the list of resources to write.

Sobrecargas

AddResource(String, Object)

Adiciona um recurso nomeado especificado como um objeto à lista de recursos a serem gravados.Adds a named resource specified as an object to the list of resources to write.

AddResource(String, String)

Adiciona um recurso de cadeia de caracteres aos recursos.Adds a string resource to the resources.

AddResource(ResXDataNode)

Adiciona um recurso nomeado especificado em um objeto ResXDataNode à lista de recursos a serem gravados.Adds a named resource specified in a ResXDataNode object to the list of resources to write.

AddResource(String, Byte[])

Adiciona um recurso nomeado especificado como uma matriz de bytes à lista de recursos a serem gravados.Adds a named resource specified as a byte array to the list of resources to write.

AddResource(String, Object)

Adiciona um recurso nomeado especificado como um objeto à lista de recursos a serem gravados.Adds a named resource specified as an object to the list of resources to write.

public:
 virtual void AddResource(System::String ^ name, System::Object ^ value);
public void AddResource (string name, object value);
abstract member AddResource : string * obj -> unit
override this.AddResource : string * obj -> unit
Public Sub AddResource (name As String, value As Object)

Parâmetros

name
String

O nome do recurso.The name of the resource.

value
Object

O valor do recurso.The value of the resource.

Implementações

Exemplos

O exemplo a seguir cria um arquivo. resx chamado CarResources.resx que armazena seis cadeias de caracteres, um ícone e dois objetos definidos pelo aplicativo (dois objetos Automobile).The following example creates a .resx file named CarResources.resx that stores six strings, an icon, and two application-defined objects (two Automobile objects). Para armazenar o ícone e os objetos Automobile, ele chama o método AddResource(String, Object).To store the icon and the Automobile objects, it calls the AddResource(String, Object) method. Observe que a classe Automobile, que é definida e instanciada no exemplo, é marcada com o atributo SerializableAttribute.Note that the Automobile class, which is defined and instantiated in the example, is tagged with the SerializableAttribute attribute.

using System;
using System.Drawing;
using System.Resources;

[Serializable()] public class Automobile
{
   private string carMake;
   private string carModel;
   private int carYear;
   private int carDoors;
   private int carCylinders;

   public Automobile(string make, string model, int year) :
                     this(make, model, year, 0, 0)
   { }

   public Automobile(string make, string model, int year,
                     int doors, int cylinders)
   {
      this.carMake = make;
      this.carModel = model;
      this.carYear = year;
      this.carDoors = doors;
      this.carCylinders = cylinders;
   }

   public string Make {
      get { return this.carMake; }
   }

   public string Model {
      get {return this.carModel; }
   }

   public int Year {
      get { return this.carYear; }
   }

   public int Doors {
      get { return this.carDoors; }
   }

   public int Cylinders {
      get { return this.carCylinders; }
   }
}

public class Example
{
   public static void Main()
   {
      // Instantiate an Automobile object.
      Automobile car1 = new Automobile("Ford", "Model N", 1906, 0, 4);
      Automobile car2 = new Automobile("Ford", "Model T", 1909, 2, 4);
      // Define a resource file named CarResources.resx.
      using (ResXResourceWriter resx = new ResXResourceWriter(@".\CarResources.resx"))
      {
         resx.AddResource("Title", "Classic American Cars");
         resx.AddResource("HeaderString1", "Make");
         resx.AddResource("HeaderString2", "Model");
         resx.AddResource("HeaderString3", "Year");
         resx.AddResource("HeaderString4", "Doors");
         resx.AddResource("HeaderString5", "Cylinders");
         resx.AddResource("Information", SystemIcons.Information);
         resx.AddResource("EarlyAuto1", car1);
         resx.AddResource("EarlyAuto2", car2);
      }
   }
}
Imports System.Drawing
Imports System.Resources

<Serializable()> Public Class Automobile
   Private carMake As String
   Private carModel As String
   Private carYear As Integer
   Private carDoors AS Integer
   Private carCylinders As Integer
   
   Public Sub New(make As String, model As String, year As Integer) 
      Me.New(make, model, year, 0, 0)   
   End Sub
   
   Public Sub New(make As String, model As String, year As Integer, 
                  doors As Integer, cylinders As Integer)
      Me.carMake = make
      Me.carModel = model
      Me.carYear = year
      Me.carDoors = doors
      Me.carCylinders = cylinders
   End Sub

   Public ReadOnly Property Make As String
      Get
         Return Me.carMake
      End Get   
   End Property       
   
   Public ReadOnly Property Model As String
      Get
         Return Me.carModel
      End Get   
   End Property       
   
   Public ReadOnly Property Year As Integer
      Get
         Return Me.carYear
      End Get   
   End Property       
   
   Public ReadOnly Property Doors As Integer
      Get
         Return Me.carDoors
      End Get   
   End Property       
   
   Public ReadOnly Property Cylinders As Integer
      Get
         Return Me.carCylinders
      End Get   
   End Property       
End Class

Module Example
   Public Sub Main()
      ' Instantiate an Automobile object.
      Dim car1 As New Automobile("Ford", "Model N", 1906, 0, 4)
      Dim car2 As New Automobile("Ford", "Model T", 1909, 2, 4)
      ' Define a resource file named CarResources.resx.
      Using resx As New ResXResourceWriter(".\CarResources.resx")
         resx.AddResource("Title", "Classic American Cars")
         resx.AddResource("HeaderString1", "Make")
         resx.AddResource("HeaderString2", "Model")
         resx.AddResource("HeaderString3", "Year")
         resx.AddResource("HeaderString4", "Doors")
         resx.AddResource("HeaderString5", "Cylinders")
         resx.AddResource("Information", SystemIcons.Information) 
         resx.AddResource("EarlyAuto1", car1)
         resx.AddResource("EarlyAuto2", car2)  
      End Using
   End Sub
End Module

Comentários

O recurso não é gravado até que Generate seja chamado.The resource is not written until Generate is called. O recurso que foi adicionado deve ser serializável.The resource that was added must be serializable.

Se o recurso que está sendo adicionado for uma cadeia de caracteres, ele será gravado como uma cadeia de caracteres; caso contrário, o recurso é serializado e armazenado em um formato binário.If the resource being added is a string, it is written as a string; otherwise, the resource is serialized and stored in a binary format.

AddResource(String, String)

Adiciona um recurso de cadeia de caracteres aos recursos.Adds a string resource to the resources.

public:
 virtual void AddResource(System::String ^ name, System::String ^ value);
public void AddResource (string name, string value);
abstract member AddResource : string * string -> unit
override this.AddResource : string * string -> unit
Public Sub AddResource (name As String, value As String)

Parâmetros

name
String

O nome do recurso.The name of the resource.

value
String

O valor do recurso.The value of the resource.

Implementações

Exemplos

O exemplo a seguir cria um arquivo. resx chamado CarResources.resx que armazena seis cadeias de caracteres, um ícone e dois objetos definidos pelo aplicativo (dois objetos Automobile).The following example creates a .resx file named CarResources.resx that stores six strings, an icon, and two application-defined objects (two Automobile objects). Para armazenar as cadeias de caracteres, ele chama o método AddResource(String, String).To store the strings, it calls the AddResource(String, String) method.

using System;
using System.Drawing;
using System.Resources;

[Serializable()] public class Automobile
{
   private string carMake;
   private string carModel;
   private int carYear;
   private int carDoors;
   private int carCylinders;

   public Automobile(string make, string model, int year) :
                     this(make, model, year, 0, 0)
   { }

   public Automobile(string make, string model, int year,
                     int doors, int cylinders)
   {
      this.carMake = make;
      this.carModel = model;
      this.carYear = year;
      this.carDoors = doors;
      this.carCylinders = cylinders;
   }

   public string Make {
      get { return this.carMake; }
   }

   public string Model {
      get {return this.carModel; }
   }

   public int Year {
      get { return this.carYear; }
   }

   public int Doors {
      get { return this.carDoors; }
   }

   public int Cylinders {
      get { return this.carCylinders; }
   }
}

public class Example
{
   public static void Main()
   {
      // Instantiate an Automobile object.
      Automobile car1 = new Automobile("Ford", "Model N", 1906, 0, 4);
      Automobile car2 = new Automobile("Ford", "Model T", 1909, 2, 4);
      // Define a resource file named CarResources.resx.
      using (ResXResourceWriter resx = new ResXResourceWriter(@".\CarResources.resx"))
      {
         resx.AddResource("Title", "Classic American Cars");
         resx.AddResource("HeaderString1", "Make");
         resx.AddResource("HeaderString2", "Model");
         resx.AddResource("HeaderString3", "Year");
         resx.AddResource("HeaderString4", "Doors");
         resx.AddResource("HeaderString5", "Cylinders");
         resx.AddResource("Information", SystemIcons.Information);
         resx.AddResource("EarlyAuto1", car1);
         resx.AddResource("EarlyAuto2", car2);
      }
   }
}
Imports System.Drawing
Imports System.Resources

<Serializable()> Public Class Automobile
   Private carMake As String
   Private carModel As String
   Private carYear As Integer
   Private carDoors AS Integer
   Private carCylinders As Integer
   
   Public Sub New(make As String, model As String, year As Integer) 
      Me.New(make, model, year, 0, 0)   
   End Sub
   
   Public Sub New(make As String, model As String, year As Integer, 
                  doors As Integer, cylinders As Integer)
      Me.carMake = make
      Me.carModel = model
      Me.carYear = year
      Me.carDoors = doors
      Me.carCylinders = cylinders
   End Sub

   Public ReadOnly Property Make As String
      Get
         Return Me.carMake
      End Get   
   End Property       
   
   Public ReadOnly Property Model As String
      Get
         Return Me.carModel
      End Get   
   End Property       
   
   Public ReadOnly Property Year As Integer
      Get
         Return Me.carYear
      End Get   
   End Property       
   
   Public ReadOnly Property Doors As Integer
      Get
         Return Me.carDoors
      End Get   
   End Property       
   
   Public ReadOnly Property Cylinders As Integer
      Get
         Return Me.carCylinders
      End Get   
   End Property       
End Class

Module Example
   Public Sub Main()
      ' Instantiate an Automobile object.
      Dim car1 As New Automobile("Ford", "Model N", 1906, 0, 4)
      Dim car2 As New Automobile("Ford", "Model T", 1909, 2, 4)
      ' Define a resource file named CarResources.resx.
      Using resx As New ResXResourceWriter(".\CarResources.resx")
         resx.AddResource("Title", "Classic American Cars")
         resx.AddResource("HeaderString1", "Make")
         resx.AddResource("HeaderString2", "Model")
         resx.AddResource("HeaderString3", "Year")
         resx.AddResource("HeaderString4", "Doors")
         resx.AddResource("HeaderString5", "Cylinders")
         resx.AddResource("Information", SystemIcons.Information) 
         resx.AddResource("EarlyAuto1", car1)
         resx.AddResource("EarlyAuto2", car2)  
      End Using
   End Sub
End Module

Observe que a classe Automobile, que é definida e instanciada no exemplo, é marcada com o atributo SerializableAttribute.Note that the Automobile class, which is defined and instantiated in the example, is tagged with the SerializableAttribute attribute.

Comentários

O recurso não é gravado até que Generate seja chamado.The resource is not written until Generate is called.

AddResource(ResXDataNode)

Adiciona um recurso nomeado especificado em um objeto ResXDataNode à lista de recursos a serem gravados.Adds a named resource specified in a ResXDataNode object to the list of resources to write.

public:
 void AddResource(System::Resources::ResXDataNode ^ node);
public void AddResource (System.Resources.ResXDataNode node);
member this.AddResource : System.Resources.ResXDataNode -> unit
Public Sub AddResource (node As ResXDataNode)

Parâmetros

node
ResXDataNode

Um objeto ResXDataNode que contém um par nome-valor do recurso.A ResXDataNode object that contains a resource name/value pair.

AddResource(String, Byte[])

Adiciona um recurso nomeado especificado como uma matriz de bytes à lista de recursos a serem gravados.Adds a named resource specified as a byte array to the list of resources to write.

public:
 virtual void AddResource(System::String ^ name, cli::array <System::Byte> ^ value);
public void AddResource (string name, byte[] value);
abstract member AddResource : string * byte[] -> unit
override this.AddResource : string * byte[] -> unit
Public Sub AddResource (name As String, value As Byte())

Parâmetros

name
String

O nome do recurso.The name of the resource.

value
Byte[]

O valor do recurso a ser adicionado como uma matriz de inteiros sem sinal de 8 bits.The value of the resource to add as an 8-bit unsigned integer array.

Implementações

Comentários

O recurso não é gravado até que Generate seja chamado.The resource is not written until Generate is called.

O recurso é serializado e armazenado em um formato binário.The resource is serialized and stored in a binary format.

Aplica-se a