ResourceWriter::AddResourceData Method (String^, String^, array<Byte>^)
Adds a unit of data as a resource to the list of resources to be written.
Assembly: mscorlib (in mscorlib.dll)
public: void AddResourceData( String^ name, String^ typeName, array<unsigned char>^ serializedData )
Parameters
- name
-
Type:
System::String^
A name that identifies the resource that contains the added data.
- typeName
-
Type:
System::String^
The type name of the added data. For more information, see the Remarks section.
- serializedData
-
Type:
array<System::Byte>^
A byte array that contains the binary representation of the added data.
| Exception | Condition |
|---|---|
| ArgumentNullException | name, typeName, or serializedData is null. |
| ArgumentException | name (or a name that varies only by capitalization) has already been added to this ResourceWriter object. |
| InvalidOperationException | The current ResourceWriter object is not initialized. The probable cause is that the ResourceWriter object is closed. |
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. 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. 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 is a string that represents the data type of the resource. It can be any of the following values:
The string representation of a ResourceTypeCode enumeration member that indicates the data type of the resource. ResourceTypeCode is a private enumeration that is used by to indicate that a special binary format is used to store one of 19 common data types. 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. In addition, the ResourceTypeCode enumeration includes the values shown in the following table.
ResourceTypeCode value
Description
ResourceTypeCode.ByteArray
The data is a byte array.
ResourceTypeCode.Null
The data is a null reference.
ResourceTypeCode.Stream
The data is stored in a stream.
A string that contains the fully qualified name of the type whose binary data is assigned to the serializedData argument (for example, System.String). 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. For example, the following string indicates that the serialized data represents an instance of the Person type in the Extensions namespace, 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
A parallel method for reading resource data written with the AddResourceData method is ResourceReader::GetResourceData.
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.
Available since 2.0