2012-03-29 27 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; 
}