ResourceWriter.AddResource Método

Definición

Agrega un recurso a la lista de recursos que se va a escribir.Adds a resource to the list of resources to be written.

Sobrecargas

AddResource(String, Byte[])

Agrega un recurso con nombre, especificado como una matriz de bytes, a la lista de recursos que se va a escribir.Adds a named resource specified as a byte array to the list of resources to be written.

AddResource(String, Stream)

Agrega un recurso con nombre, especificado como una secuencia, a la lista de recursos que se va a escribir.Adds a named resource specified as a stream to the list of resources to be written.

AddResource(String, Object)

Agrega un recurso con nombre, especificado como una matriz de bytes, a la lista de recursos que se va a escribir.Adds a named resource specified as an object to the list of resources to be written.

AddResource(String, String)

Agrega un recurso de cadena a la lista de recursos que se va a escribir.Adds a string resource to the list of resources to be written.

AddResource(String, Stream, Boolean)

Agrega un recurso con nombre especificado como una secuencia a la lista de recursos que se va a escribir y especifica si se debe cerrar la secuencia después de llamar al método Generate().Adds a named resource specified as a stream to the list of resources to be written, and specifies whether the stream should be closed after the Generate() method is called.

AddResource(String, Byte[])

Agrega un recurso con nombre, especificado como una matriz de bytes, a la lista de recursos que se va a escribir.Adds a named resource specified as a byte array to the list of resources to be written.

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

Nombre del recurso.The name of the resource.

value
Byte[]

Valor del recurso como matriz de enteros de 8 bits sin signo.Value of the resource as an 8-bit unsigned integer array.

Implementaciones

Excepciones

name (o un nombre que varía sólo en mayúsculas y minúsculas) ya se ha agregado a este ResourceWriter.name (or a name that varies only by capitalization) has already been added to this ResourceWriter.

El parámetro name es null.The name parameter is null.

Se ha cerrado este ResourceWriter y su tabla no está disponible.This ResourceWriter has been closed and its hash table is unavailable.

Ejemplos

En el ejemplo siguiente se AddResource(String, Byte[]) usa el método para agregar una imagen de gráficos que se ha leído como una matriz de bytes en un ResourceWriter objeto.The following example uses the AddResource(String, Byte[]) method to add a graphics image that has been read as an array of bytes to a ResourceWriter object.

using System;
using System.IO;
using System.Resources;

public class Example
{
   public static void Main()
   {
      // Get the image as an array of bytes.
      FileStream byteStream = new FileStream("AppIcon.jpg", FileMode.Open);
      Byte[] bytes = new Byte[(int) byteStream.Length];
      byteStream.Read(bytes, 0, (int) byteStream.Length);
      
      // Create the resource file.
      using (ResourceWriter rw = new ResourceWriter(@".\UIImages.resources")) {
         rw.AddResource("AppIcon", byteStream);
         // Add any other resources.
      }
   }
}
Imports System.IO
Imports System.Resources

Module Example
   Public Sub Main()                      
      ' Get the image as an array of bytes.
      Dim byteStream As New FileStream("AppIcon.jpg", Filemode.Open)
      Dim bytes(CInt(byteStream.Length - 1)) As Byte
      byteStream.Read(bytes, 0, CInt(byteStream.Length))
      
      ' Create the resource file.
      Using rw As New ResourceWriter(".\UIImages.resources")
         rw.AddResource("AppIcon", byteStream)
         ' Add any other resources.
      End Using
   End Sub
End Module

Comentarios

El recurso no se escribe hasta Generate que se llama a.The resource is not written until Generate is called.

Puede recuperar los recursos escritos por el AddResource(String, Byte[]) método llamando al ResourceManager.GetStream método.You can retrieve the resources written by the AddResource(String, Byte[]) method by calling the ResourceManager.GetStream method.

Consulte también:

AddResource(String, Stream)

Agrega un recurso con nombre, especificado como una secuencia, a la lista de recursos que se va a escribir.Adds a named resource specified as a stream to the list of resources to be written.

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

Parámetros

name
String

Nombre del recurso que se va a agregar.The name of the resource to add.

value
Stream

Valor del recurso que se va a agregar.The value of the resource to add. El recurso debe admitir la propiedad Length.The resource must support the Length property.

Excepciones

name (o un nombre que varía sólo en mayúsculas y minúsculas) ya se ha agregado a este ResourceWriter.name (or a name that varies only by capitalization) has already been added to this ResourceWriter.

O bien-or- La secuencia no admite la propiedad Length.The stream does not support the Length property.

name o value es null.name or value is null.

La clase ResourceWriter se ha cerrado.This ResourceWriter has been closed.

Ejemplos

En el ejemplo siguiente se AddResource(String, Stream) usa el método para agregar una imagen de gráficos que se ha MemoryStream guardado en un ResourceWriter objeto en un objeto.The following example uses the AddResource(String, Stream) method to add a graphics image that has been saved to a MemoryStream object to a ResourceWriter object.

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Resources;

public class Example
{
   public static void Main()
   {
      // Bitmap as stream
      MemoryStream bitmapStream = new MemoryStream();
      Bitmap bmp = new Bitmap(@".\\AppImage.jpg");
      bmp.Save(bitmapStream, ImageFormat.Jpeg);
          
      using (ResourceWriter rw = new ResourceWriter(@".\UIImages.resources"))
      {
         rw.AddResource("Bitmap", bitmapStream);
         // Add other resources.
      }
   }
}
Imports System.Drawing
Imports System.IO
Imports System.Resources

Module Example
   Public Sub Main()
      ' Bitmap as stream
      Dim bitmapStream As New MemoryStream()
      Dim bmp As New Bitmap(".\\AppImage.jpg")
      bmp.Save(bitmapStream, Imaging.ImageFormat.Jpeg)
          
      Using rw As New ResourceWriter(".\UIImages.resources")
         rw.AddResource("Bitmap", bitmapStream)
         ' Add other resources.
      End Using
   End Sub
End Module

Comentarios

Puede especificar cualquier secuencia que admita la Stream.Length propiedad para. valueYou can specify any stream that supports the Stream.Length property for value.

Puede recuperar los recursos escritos por el AddResource(String, Stream) método llamando al ResourceManager.GetStream método.You can retrieve the resources written by the AddResource(String, Stream) method by calling the ResourceManager.GetStream method.

Consulte también:

AddResource(String, Object)

Agrega un recurso con nombre, especificado como una matriz de bytes, a la lista de recursos que se va a escribir.Adds a named resource specified as an object to the list of resources to be written.

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

Nombre del recurso.The name of the resource.

value
Object

Valor del recurso.The value of the resource.

Implementaciones

Excepciones

name (o un nombre que varía sólo en mayúsculas y minúsculas) ya se ha agregado a este ResourceWriter.name (or a name that varies only by capitalization) has already been added to this ResourceWriter.

El parámetro name es null.The name parameter is null.

Se ha cerrado este ResourceWriter y su tabla no está disponible.This ResourceWriter has been closed and its hash table is unavailable.

Ejemplos

En el ejemplo siguiente se AddResource(String, Object) usa el método para agregar datos de objeto a un archivo de recursos binario.The following example uses the AddResource(String, Object) method to add object data to a binary resources file.

using System;
using System.Resources;

public class Example
{
   public static void Main()
   {
      DonorColumns columns = new DonorColumns("Emplyee #", "Name", 
                                              "Total Amount", "Last Donation Date",
                                              "Last Donation Amount");
      ResourceWriter resFile = new ResourceWriter(@".\UIResources.resources");
      resFile.AddResource("Title", "Corporate Gold Star Donors");
      resFile.AddResource("NColumns", 5);
      resFile.AddResource("AppDate", new DateTime(2011, 5, 28));
      resFile.AddResource("AppVersion", new Version(1, 0, 217));
      resFile.AddResource("HRVersion", true);
      resFile.Generate();
      resFile.Close();               
   }
}

// Class to hold potentially localized column names.
[Serializable] public class DonorColumns
{
   readonly string ID;
   readonly string Name;
   readonly string Total;
   readonly string Last;
   readonly string Amt;

   public DonorColumns(string id, string name, string total, 
                  string last, string amt)
   {                  
      this.ID = id;
      this.Name = name;
      this.Total = total;
      this.Last = last;
      this.Amt = amt;                        
   }   
}

DonorColumnses una clase personalizada cuyos campos contienen los nombres de las columnas que se van a mostrar en la interfaz de usuario.DonorColumns is a custom class whose fields contain the names of columns to be displayed in the user interface. Tenga en cuenta que la clase se marca SerializableAttribute con el atributo.Note that the class is marked with the SerializableAttribute attribute. Normalmente, la clase se definiría en un ensamblado independiente y se proporcionaría al compilador una referencia a ella en tiempo de compilación.Ordinarily, the class would be defined in a separate assembly, and a reference to it would be provided to the compiler at compile time.

Comentarios

value debe ser serializable.value must be serializable.

El recurso no se escribe hasta que Generate se llama al método.The resource is not written until the Generate method is called.

Puede recuperar los recursos escritos por el AddResource(String, Object) método llamando al ResourceManager.GetObject método.You can retrieve the resources written by the AddResource(String, Object) method by calling the ResourceManager.GetObject method.

Consulte también:

AddResource(String, String)

Agrega un recurso de cadena a la lista de recursos que se va a escribir.Adds a string resource to the list of resources to be written.

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

Nombre del recurso.The name of the resource.

value
String

Valor del recurso.The value of the resource.

Implementaciones

Excepciones

name (o un nombre que varía sólo en mayúsculas y minúsculas) ya se ha agregado a este ResourceWriter.name (or a name that varies only by capitalization) has already been added to this ResourceWriter.

El parámetro name es null.The name parameter is null.

Se ha cerrado este ResourceWriter y su tabla no está disponible.This ResourceWriter has been closed and its hash table is unavailable.

Ejemplos

En el ejemplo siguiente se AddResource usa el método para agregar recursos de ResourceWriter cadena a un objeto.The following example uses the AddResource method to add string resources to a ResourceWriter object.

using namespace System;
using namespace System::Resources;
using namespace System::IO;
int main()
{
   
   // Create a file stream to encapsulate items.resources.
   FileStream^ fs = gcnew FileStream( "items.resources",FileMode::OpenOrCreate,FileAccess::Write );
   
   // Open a resource writer to write from the stream.
   IResourceWriter^ writer = gcnew ResourceWriter( fs );
   
   // Add resources to the resource writer.
   writer->AddResource( "String 1", "First String" );
   writer->AddResource( "String 2", "Second String" );
   writer->AddResource( "String 3", "Third String" );
   
   // Write the resources to the stream, and close it.
   writer->Close();
}

using System;
using System.Resources;
using System.IO;

public class WriteResources 
{
    public static void Main(string[] args) 
    {  
        // Create a file stream to encapsulate items.resources.
        FileStream fs = new FileStream("items.resources", 
        FileMode.OpenOrCreate,FileAccess.Write);

        // Open a resource writer to write from the stream.
        IResourceWriter writer = new ResourceWriter(fs);
    
        // Add resources to the resource writer.
        writer.AddResource("String 1", "First String");
        writer.AddResource("String 2", "Second String");
        writer.AddResource("String 3", "Third String");

        // Write the resources to the stream, and close it.
        writer.Close();
    }
}
Imports System.Resources
Imports System.IO

Public Class WriteResources
   
    Public Shared Sub Main(args() As String)
        ' Create a file stream to encapsulate items.resources.
        Dim fs As New FileStream("items.resources", _
           FileMode.OpenOrCreate, FileAccess.Write)
      
        ' Open a resource writer to write from the stream.
        Dim writer = New ResourceWriter(fs)
      
        ' Add resources to the resource writer.
        writer.AddResource("String 1", "First String")
        writer.AddResource("String 2", "Second String")
        writer.AddResource("String 3", "Third String")
      
        ' Write the resources to the stream, and close it.
        writer.Close()
    End Sub

End Class

Comentarios

El recurso no se escribe hasta Generate que se llama a.The resource is not written until Generate is called.

Puede recuperar los recursos escritos por el AddResource(String, String) método llamando al ResourceManager.GetString método.You can retrieve the resources written by the AddResource(String, String) method by calling the ResourceManager.GetString method.

Consulte también:

AddResource(String, Stream, Boolean)

Agrega un recurso con nombre especificado como una secuencia a la lista de recursos que se va a escribir y especifica si se debe cerrar la secuencia después de llamar al método Generate().Adds a named resource specified as a stream to the list of resources to be written, and specifies whether the stream should be closed after the Generate() method is called.

public:
 void AddResource(System::String ^ name, System::IO::Stream ^ value, bool closeAfterWrite);
public void AddResource (string name, System.IO.Stream value, bool closeAfterWrite);
member this.AddResource : string * System.IO.Stream * bool -> unit
Public Sub AddResource (name As String, value As Stream, closeAfterWrite As Boolean)

Parámetros

name
String

Nombre del recurso que se va a agregar.The name of the resource to add.

value
Stream

Valor del recurso que se va a agregar.The value of the resource to add. El recurso debe admitir la propiedad Length.The resource must support the Length property.

closeAfterWrite
Boolean

true para cerrar la secuencia después de llamar al método Generate(); false en otro caso.true to close the stream after the Generate() method is called; otherwise, false.

Excepciones

name (o un nombre que varía sólo en mayúsculas y minúsculas) ya se ha agregado a este ResourceWriter.name (or a name that varies only by capitalization) has already been added to this ResourceWriter.

O bien-or- La secuencia no admite la propiedad Length.The stream does not support the Length property.

name o value es null.name or value is null.

La clase ResourceWriter se ha cerrado.This ResourceWriter has been closed.

Ejemplos

En el ejemplo siguiente se AddResource(String, Stream, Boolean) usa el método para agregar una imagen de gráficos que se ha MemoryStream guardado en un ResourceWriter objeto en un objeto.The following example uses the AddResource(String, Stream, Boolean) method to add a graphics image that has been saved to a MemoryStream object to a ResourceWriter object.

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Resources;

public class Example
{
   public static void Main()
   {
      // Bitmap as stream
      MemoryStream bitmapStream = new MemoryStream();
      Bitmap bmp = new Bitmap(@".\\AppImage.jpg");
      bmp.Save(bitmapStream, ImageFormat.Jpeg);
          
      ResourceWriter rw = new ResourceWriter(@".\UIImages.resources");
      rw.AddResource("Bitmap", bitmapStream, true);
      // Add other resources.
      rw.Generate();
   }
}
Imports System.Drawing
Imports System.IO
Imports System.Resources

Module Example
   Public Sub Main()
      ' Bitmap as stream
      Dim bitmapStream As New MemoryStream()
      Dim bmp As New Bitmap(".\\AppImage.jpg")
      bmp.Save(bitmapStream, Imaging.ImageFormat.Jpeg)
          
      Dim rw As New ResourceWriter(".\UIImages.resources")
      rw.AddResource("Bitmap", bitmapStream, True)
      ' Add other resources.
      rw.Generate()
   End Sub
End Module

Comentarios

Puede especificar cualquier secuencia que admita la Stream.Length propiedad para. valueYou can specify any stream that supports the Stream.Length property for value.

Puede recuperar los recursos escritos por el AddResource(String, Stream, Boolean) método llamando al ResourceManager.GetStream método.You can retrieve the resources written by the AddResource(String, Stream, Boolean) method by calling the ResourceManager.GetStream method.

Consulte también:

Se aplica a