本文整理汇总了C#中System.Reflection.Internal.MemoryBlock.PeekUInt32方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryBlock.PeekUInt32方法的具体用法?C# MemoryBlock.PeekUInt32怎么用?C# MemoryBlock.PeekUInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Internal.MemoryBlock
的用法示例。
在下文中一共展示了MemoryBlock.PeekUInt32方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFromMemoryBlock
public unsafe void ReadFromMemoryBlock()
{
byte[] buffer = new byte[4] { 0, 1, 0, 2 };
fixed (byte* bufferPtr = buffer)
{
var block = new MemoryBlock(bufferPtr, buffer.Length);
Assert.Throws<BadImageFormatException>(() => block.PeekUInt32(Int32.MaxValue));
Assert.Throws<BadImageFormatException>(() => block.PeekUInt32(-1));
Assert.Throws<BadImageFormatException>(() => block.PeekUInt32(Int32.MinValue));
Assert.Throws<BadImageFormatException>(() => block.PeekUInt32(4));
Assert.Throws<BadImageFormatException>(() => block.PeekUInt32(1));
Assert.Equal(0x02000100U, block.PeekUInt32(0));
Assert.Throws<BadImageFormatException>(() => block.PeekUInt16(Int32.MaxValue));
Assert.Throws<BadImageFormatException>(() => block.PeekUInt16(-1));
Assert.Throws<BadImageFormatException>(() => block.PeekUInt16(Int32.MinValue));
Assert.Throws<BadImageFormatException>(() => block.PeekUInt16(4));
Assert.Equal(0x0200, block.PeekUInt16(2));
int bytesRead;
MetadataStringDecoder stringDecoder = MetadataStringDecoder.DefaultUTF8;
Assert.Throws<BadImageFormatException>(() => block.PeekUtf8NullTerminated(Int32.MaxValue, null, stringDecoder, out bytesRead));
Assert.Throws<BadImageFormatException>(() => block.PeekUtf8NullTerminated(-1, null, stringDecoder, out bytesRead));
Assert.Throws<BadImageFormatException>(() => block.PeekUtf8NullTerminated(Int32.MinValue, null, stringDecoder, out bytesRead));
Assert.Throws<BadImageFormatException>(() => block.PeekUtf8NullTerminated(5, null, stringDecoder, out bytesRead));
Assert.Throws<BadImageFormatException>(() => block.GetMemoryBlockAt(-1, 1));
Assert.Throws<BadImageFormatException>(() => block.GetMemoryBlockAt(1, -1));
Assert.Throws<BadImageFormatException>(() => block.GetMemoryBlockAt(0, -1));
Assert.Throws<BadImageFormatException>(() => block.GetMemoryBlockAt(-1, 0));
Assert.Throws<BadImageFormatException>(() => block.GetMemoryBlockAt(-Int32.MaxValue, Int32.MaxValue));
Assert.Throws<BadImageFormatException>(() => block.GetMemoryBlockAt(Int32.MaxValue, -Int32.MaxValue));
Assert.Throws<BadImageFormatException>(() => block.GetMemoryBlockAt(Int32.MaxValue, Int32.MaxValue));
Assert.Throws<BadImageFormatException>(() => block.GetMemoryBlockAt(block.Length, -1));
Assert.Throws<BadImageFormatException>(() => block.GetMemoryBlockAt(-1, block.Length));
Assert.Equal("\u0001", block.PeekUtf8NullTerminated(1, null, stringDecoder, out bytesRead));
Assert.Equal(bytesRead, 2);
Assert.Equal("\u0002", block.PeekUtf8NullTerminated(3, null, stringDecoder, out bytesRead));
Assert.Equal(bytesRead, 1);
Assert.Equal("", block.PeekUtf8NullTerminated(4, null, stringDecoder, out bytesRead));
Assert.Equal(bytesRead, 0);
byte[] helloPrefix = Encoding.UTF8.GetBytes("Hello");
Assert.Equal("Hello\u0001", block.PeekUtf8NullTerminated(1, helloPrefix, stringDecoder, out bytesRead));
Assert.Equal(bytesRead, 2);
Assert.Equal("Hello\u0002", block.PeekUtf8NullTerminated(3, helloPrefix, stringDecoder, out bytesRead));
Assert.Equal(bytesRead, 1);
Assert.Equal("Hello", block.PeekUtf8NullTerminated(4, helloPrefix, stringDecoder, out bytesRead));
Assert.Equal(bytesRead, 0);
}
}