ResourceReader.GetResourceData(String, String, Byte[]) 方法

定义

从打开的资源文件或流检索指定资源的类型名称和数据。Retrieves the type name and data of a named resource from an open resource file or stream.

public:
 void GetResourceData(System::String ^ resourceName, [Runtime::InteropServices::Out] System::String ^ % resourceType, [Runtime::InteropServices::Out] cli::array <System::Byte> ^ % resourceData);
public void GetResourceData (string resourceName, out string resourceType, out byte[] resourceData);
member this.GetResourceData : string * string * Byte[] -> unit
Public Sub GetResourceData (resourceName As String, ByRef resourceType As String, ByRef resourceData As Byte())

参数

resourceName
String

资源的名称。The name of a resource.

resourceType
String

当此方法返回时,包含表示检索资源的类型名称的字符串。When this method returns, contains a string that represents the type name of the retrieved resource. 此参数未经初始化即被传递。This parameter is passed uninitialized.

resourceData
Byte[]

此方法返回时,包含一个字节数组,该字节数组为所检索类型的二进制表示形式。When this method returns, contains a byte array that is the binary representation of the retrieved type. 此参数未经初始化即被传递。This parameter is passed uninitialized.

例外

resourceNamenullresourceName is null.

resourceName 不存在。resourceName does not exist.

resourceName 具有无效的类型。resourceName has an invalid type.

检索的资源数据已损坏。The retrieved resource data is corrupt.

当前 ResourceReader 对象未初始化,可能因其已被关闭。The current ResourceReader object is not initialized, probably because it is closed.

注解

GetResourceData方法检索指定资源的值作为字节数组。The GetResourceData method retrieves the value of a named resource as a byte array. Value 属性尝试检索资源的值时,通常会使用该属性引发异常。It is typically used when the Value property throws an exception when it tries to retrieve the value of a resource.

resourceType 表示资源的数据类型的字符串。resourceType is a string that represents the data type of the resource. 可以是以下任一值:It can be any of the following values:

  • ResourceTypeCode指示资源的数据类型的枚举成员的字符串表示形式。The string representation of a ResourceTypeCode enumeration member that indicates the data type of the resource. ResourceTypeCode 是使用的私有枚举。指示使用特殊的二进制格式存储19个常见数据类型之一。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. 其中包括 .NET Framework 基元数据类型 (、、、、、、、、、、、、 Boolean Byte Char Decimal Double Int16 Int32 Int64 Single SByte UInt16 UInt32 UInt64) ,以及 StringDateTime 和, TimeSpan 另外, ResourceTypeCode 枚举还包括下表中显示的值。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 值ResourceTypeCode value 说明Description
    ResourceTypeCode.ByteArray 数据是字节数组。The data is a byte array. 此数据类型通常是通过调用方法导致的 ResourceWriter.AddResource(String, Byte[])This data type commonly results from the call to the ResourceWriter.AddResource(String, Byte[]) method.
    ResourceTypeCode.Null 数据为空引用。The data is a null reference. 此数据类型通常是 ResourceWriter.AddResource(String, Object) 使用值为的对象调用方法导致的 nullThis data type commonly results from the call to the ResourceWriter.AddResource(String, Object) method with an object whose value is null.
    ResourceTypeCode.Stream 数据存储在流中。The data is stored in a stream. 此数据类型通常是通过调用 ResourceWriter.AddResource(String, Stream) 或方法生成的 ResourceWriter.AddResource(String, Stream, Boolean)This data type commonly results from the call to the ResourceWriter.AddResource(String, Stream) or ResourceWriter.AddResource(String, Stream, Boolean) method.

    假定 resourceData 未损坏,则通常可以通过调用或方法将其从字节数组转换回其原始值 BitConverter BinaryReaderAssuming that resourceData has not been corrupted, it can usually be converted from a byte array back to its original value by calling a BitConverter or BinaryReader method.

  • 一个字符串,其中包含类型的完全限定名称,该类型的序列化数据将分配给 resourceData 参数 (例如 System.String) 。A string that contains the fully qualified name of the type whose serialized data is assigned to the resourceData argument (for example, System.String). 此外,对于不属于 .NET Framework 类库的类型,该字符串包含包含该类型的程序集的名称、版本、区域性和公钥。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. 例如,下面的字符串表示序列化数据表示 Person 命名空间中类型的一个实例,该类型在 Extensions 名为 Utility 的程序集的版本1.0 中,该程序集没有公共密钥,也没有指定的区域性。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

    假设未 resourceData 损坏并且源类型可用,则 resourceData 可以通过将字节数组转换为 Stream 对象并将流传递到方法,将字节数组转换回其原始值 BinaryFormatter.DeserializeAssuming that resourceData has not been corrupted and that the source type is available, resourceData can be converted from a byte array back to its original value by converting the byte array to a Stream object and passing the stream to the BinaryFormatter.Deserialize method.

  • 用于描述方法调用中的数据类型的字符串 ResourceWriter.AddResourceDataThe string used to describe the data type in the ResourceWriter.AddResourceData method call.

适用于

另请参阅