ResourceWriter.AddResourceData(String, String, Byte[]) Método
Definição
Adiciona uma unidade de dados como um recurso à lista de recursos a serem gravados.Adds a unit of data as a resource to the list of resources to be written.
public:
void AddResourceData(System::String ^ name, System::String ^ typeName, cli::array <System::Byte> ^ serializedData);
public void AddResourceData (string name, string typeName, byte[] serializedData);
member this.AddResourceData : string * string * byte[] -> unit
Public Sub AddResourceData (name As String, typeName As String, serializedData As Byte())
Parâmetros
- name
- String
Um nome que identifica o recurso que contém os dados adicionados.A name that identifies the resource that contains the added data.
- typeName
- String
O nome do tipo dos dados adicionados.The type name of the added data.
- serializedData
- Byte[]
Uma matriz de bytes que contém a representação binária dos dados adicionados.A byte array that contains the binary representation of the added data.
Exceções
name, typeName ou serializedData é null.name, typeName, or serializedData is null.
name (ou um nome que varia de acordo apenas com maiúsculas e minúsculas) já foi adicionado a este objeto ResourceWriter.name (or a name that varies only by capitalization) has already been added to this ResourceWriter object.
O objeto ResourceWriter não foi inicializado.The current ResourceWriter object is not initialized. A causa provável é que o objeto ResourceWriter está fechado.The probable cause is that the ResourceWriter object is closed.
Exemplos
O exemplo a seguir usa o AddResourceData método para gravar dois valores inteiros em um arquivo. Resources e, em seguida, usa um ResourceReader objeto para recuperá-los.The following example uses the AddResourceData method to write two integer values to a .resources file, and then uses a ResourceReader object to retrieve them.
using System;
using System.Collections;
using System.Resources;
public class Example
{
public static void Main()
{
ResourceWriter rw = new ResourceWriter(@".\TypeResources.resources");
int n1 = 1032;
rw.AddResourceData("Integer1", "ResourceTypeCode.Int32", BitConverter.GetBytes(n1));
int n2 = 2064;
rw.AddResourceData("Integer2", "ResourceTypeCode.Int32", BitConverter.GetBytes(n2));
rw.Generate();
rw.Close();
ResourceReader rr = new ResourceReader(@".\TypeResources.resources");
IDictionaryEnumerator e = rr.GetEnumerator();
while (e.MoveNext())
Console.WriteLine("{0}: {1}", e.Key, e.Value);
}
}
// The example displays the following output:
// Integer2: 2064
// Integer1: 1032
Imports System.Collections
Imports System.Resources
Module Example
Public Sub Main()
Dim rw As New ResourceWriter(".\TypeResources.resources")
Dim n1 As Integer = 1032
rw.AddResourceData("Integer1", "ResourceTypeCode.Int32", BitConverter.GetBytes(n1))
Dim n2 As Integer = 2064
rw.AddResourceData("Integer2", "ResourceTypeCode.Int32", BitConverter.GetBytes(n2))
rw.Generate()
rw.Close()
Dim rr As New ResourceReader(".\TypeResources.resources")
Dim e As IDictionaryEnumerator = rr.GetEnumerator()
Do While e.MoveNext()
Console.WriteLine("{0}: {1}", e.Key, e.Value)
Loop
End Sub
End Module
' The example displays the following output:
' Integer2: 2064
' Integer1: 1032
Comentários
Use o AddResourceData método para adicionar um recurso em formato binário (ou seja, como uma matriz de bytes) à lista de recursos a serem gravados.Use the AddResourceData method to add a resource in binary form (that is, as an array of bytes) to the list of resources to be written. Você deve especificar o nome do recurso, o nome do tipo dos dados contidos no recurso e a representação binária dos dados em si.You must specify the name of the resource, the type name of the data contained in the resource, and the binary representation of the data itself. Depois de adicionar cada recurso necessário, use o Generate método para gravar a lista de recursos no arquivo de recursos ou no fluxo que foi especificado no ResourceWriter Construtor.After you have added each resource you require, use the Generate method to write the list of resources to the resources file or stream that was specified in the ResourceWriter constructor.
typeName é uma cadeia de caracteres que representa o tipo de dados do recurso.typeName is a string that represents the data type of the resource. Pode ser qualquer um dos seguintes valores:It can be any of the following values:
A representação de cadeia de caracteres de um
ResourceTypeCodemembro de enumeração que indica o tipo de dados do recurso.The string representation of aResourceTypeCodeenumeration member that indicates the data type of the resource.ResourceTypeCodeé uma enumeração privada usada pelo Resgen.exe para indicar que um formato binário especial é usado para armazenar um de 19 tipos de dados comuns.ResourceTypeCodeis a private enumeration that is used by Resgen.exe to indicate that a special binary format is used to store one of 19 common data types. Isso inclui os tipos de dados primitivos .NET Framework (,,,,,,,,,,, Boolean Byte Char Decimal Double Int16 Int32 Int64 Single SByte UInt16 UInt32 , UInt64 ), bem como String , DateTime e TimeSpan .These include the .NET Framework primitive data types (Boolean, Byte, Char, Decimal, Double, Int16, Int32, Int64, Single, SByte, UInt16, UInt32, UInt64), as well as String, DateTime, and TimeSpan. Além disso, aResourceTypeCodeenumeração inclui os valores mostrados na tabela a seguir.In addition, theResourceTypeCodeenumeration includes the values shown in the following table.Valor ResourceTypeCodeResourceTypeCodevalueDescriçãoDescription ResourceTypeCode.ByteArrayOs dados são uma matriz de bytes.The data is a byte array. ResourceTypeCode.NullOs dados são uma referência nula.The data is a null reference. ResourceTypeCode.StreamOs dados são armazenados em um fluxo.The data is stored in a stream. Uma cadeia de caracteres que contém o nome totalmente qualificado do tipo cujos dados binários são atribuídos ao
serializedDataargumento (por exemplo,System.String).A string that contains the fully qualified name of the type whose binary data is assigned to theserializedDataargument (for example,System.String). Além disso, para tipos que não fazem parte do .NET Framework biblioteca de classes, a cadeia de caracteres inclui o nome, a versão, a cultura e a chave pública do assembly que contém o tipo.In addition, for types that are not part of the .NET Framework class library, the string includes the name, version, culture, and public key of the assembly that contains the type. Por exemplo, a cadeia de caracteres a seguir indica que os dados serializados representam uma instância doPersontipo noExtensionsnamespace, que é encontrado na versão 1,0 de um assembly chamado Utility que não tem nenhuma chave pública e nenhuma cultura designada.For example, the following string indicates that the serialized data represents an instance of thePersontype in theExtensionsnamespace, which is found in version 1.0 of an assembly named Utility that has no public key and no designated culture.Extensions.Person, Utility, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Um método paralelo para ler dados de recursos gravados com o AddResourceData método é ResourceReader.GetResourceData .A parallel method for reading resource data written with the AddResourceData method is ResourceReader.GetResourceData.