2012-03-29 58 views
2

我目前正在开发一个应用程序以使用WAV文件。我希望能够以其本机类型显示结构中的信息,但C#将char视为16位值。Visual Studio调试 - 本机类型

的四个字节ChunkID0 ... 3都应该包含 'R' 'I' 'F' 'F'

[StructLayout(LayoutKind.Explicit, Size = 12, Pack = 1)] 
public unsafe struct RiffDescriptor 
{ 
    [FieldOffset(0)] 
    public byte ChunkID_0; 

    [FieldOffset(1)] 
    public byte ChunkID_1; 

    ... 
} 

我想要的调试器,以显示作为块ID 'R' 而不是122 。

有什么想法?

+0

为什么不把它声明为'char'呢? – Jon 2012-03-29 22:50:41

+0

你如何将122映射到R? – JaredPar 2012-03-29 22:50:41

+0

@Jon C#声明char是一个16位类型。我想保留原来的类型。 – clamport 2012-03-29 23:06:56

回答

1
public class RiffDescriptor 
{ 
    public RiffDescriptor(BinaryReader b) 
    { 
     // Read the ChunkID - Should be RIFF 
     ChunkID = b.ReadBytes(4); 

     // Read the ChunkSize 
     ChunkSize = b.ReadUInt32(); 

     // Read the Format - Should be WAVE 
     Format = b.ReadBytes(4); 
    } 

    [DebuggerDisplay("ChunkID = {System.Text.Encoding.Default.GetString(ChunkID)}")] 
    public byte[] ChunkID; 

    public UInt32 ChunkSize; 

    [DebuggerDisplay("Format = {System.Text.Encoding.Default.GetString(Format)}")] 
    public byte[] Format; 
}