本文整理汇总了C#中Microsoft.Cci.BlobBuilder类的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder类的具体用法?C# BlobBuilder怎么用?C# BlobBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlobBuilder类属于Microsoft.Cci命名空间,在下文中一共展示了BlobBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteData
public void WriteData(BlobBuilder resourceWriter)
{
if (_fileReference == null)
{
try
{
using (Stream stream = _streamProvider())
{
if (stream == null)
{
throw new InvalidOperationException(CodeAnalysisResources.ResourceStreamProviderShouldReturnNonNullStream);
}
var count = (int)(stream.Length - stream.Position);
resourceWriter.WriteInt32(count);
resourceWriter.Write(stream, count);
resourceWriter.Align(8);
}
}
catch (Exception e)
{
throw new ResourceException(_name, e);
}
}
}
示例2: WriteData
public void WriteData(BlobBuilder resourceWriter)
{
if (_fileReference == null)
{
try
{
using (Stream stream = _streamProvider())
{
if (stream == null)
{
throw new InvalidOperationException(CodeAnalysisResources.ResourceStreamProviderShouldReturnNonNullStream);
}
var count = (int)(stream.Length - stream.Position);
resourceWriter.WriteInt32(count);
int bytesWritten = resourceWriter.TryWriteBytes(stream, count);
if (bytesWritten != count)
{
throw new EndOfStreamException(
string.Format(CultureInfo.CurrentUICulture, CodeAnalysisResources.ResourceStreamEndedUnexpectedly, bytesWritten, count));
}
resourceWriter.Align(8);
}
}
catch (Exception e)
{
throw new ResourceException(_name, e);
}
}
}
示例3: TestContentEquals
private void TestContentEquals(byte[] left, byte[] right)
{
var builder1 = new BlobBuilder(0);
builder1.WriteBytes(left);
var builder2 = new BlobBuilder(0);
builder2.WriteBytes(right);
bool expected = ByteSequenceComparer.Equals(left, right);
Assert.Equal(expected, builder1.ContentEquals(builder2));
}
示例4: Ctor
public void Ctor()
{
var builder = new BlobBuilder();
Assert.Equal(BlobBuilder.DefaultChunkSize, builder.BufferSize);
builder = new BlobBuilder(0);
Assert.Equal(BlobBuilder.MinChunkSize, builder.BufferSize);
builder = new BlobBuilder(10001);
Assert.Equal(10001, builder.BufferSize);
}
示例5: ContentEquals
public void ContentEquals()
{
var builder = new BlobBuilder();
Assert.True(builder.ContentEquals(builder));
Assert.False(builder.ContentEquals(null));
TestContentEquals(new byte[] { }, new byte[] { });
TestContentEquals(new byte[] { 1 }, new byte[] { });
TestContentEquals(new byte[] { }, new byte[] { 1 });
TestContentEquals(new byte[] { 1 }, new byte[] { 1 });
TestContentEquals(
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 });
TestContentEquals(
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });
TestContentEquals(
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 },
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 });
TestContentEquals(
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 },
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });
TestContentEquals(
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 },
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });
TestContentEquals(
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 },
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });
TestContentEquals(
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 },
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 });
TestContentEquals(
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 },
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 });
TestContentEquals(
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 },
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 });
TestContentEquals(
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 },
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 });
}
示例6: PdbLogger
internal PdbLogger(bool logging)
{
_logging = logging;
if (logging)
{
_logData = BlobBuilder.GetInstance();
_hashAlgorithm = new SHA1CryptoServiceProvider();
Debug.Assert(_hashAlgorithm.SupportsTransform);
}
else
{
_logData = null;
_hashAlgorithm = null;
}
}
示例7: BlobBuilder
public BlobBuilder(int size = DefaultChunkSize)
{
if (size < 0)
{
throw new ArgumentOutOfRangeException(nameof(size));
}
// the writer assumes little-endian architecture:
if (!BitConverter.IsLittleEndian)
{
throw new PlatformNotSupportedException();
}
_nextOrPrevious = this;
_buffer = new byte[Math.Max(MinChunkSize, size)];
}
示例8: CountClear
public void CountClear()
{
var builder = new BlobBuilder();
Assert.Equal(0, builder.Count);
builder.WriteByte(1);
Assert.Equal(1, builder.Count);
builder.WriteInt32(4);
Assert.Equal(5, builder.Count);
builder.Clear();
Assert.Equal(0, builder.Count);
builder.WriteInt64(1);
Assert.Equal(8, builder.Count);
AssertEx.Equal(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, builder.ToArray());
}
示例9: PdbLogger
internal PdbLogger(bool logging)
{
_logging = logging;
if (logging)
{
// do not get this from pool
// we need a fairly large buffer here (where the pool typically contains small ones)
// and we need just one per compile session
// pooling will be couter-productive in such scenario
_logData = new BlobBuilder(bufferFlushLimit);
_hashAlgorithm = new SHA1CryptoServiceProvider();
Debug.Assert(_hashAlgorithm.SupportsTransform);
}
else
{
_logData = null;
_hashAlgorithm = null;
}
}
示例10: WritePrimitive
public void WritePrimitive()
{
var writer = new BlobBuilder(4);
writer.WriteUInt32(0x11223344);
writer.WriteUInt16(0x5566);
writer.WriteByte(0x77);
writer.WriteUInt64(0x8899aabbccddeeff);
writer.WriteInt32(-1);
writer.WriteInt16(-2);
writer.WriteSByte(-3);
writer.WriteBoolean(true);
writer.WriteBoolean(false);
writer.WriteInt64(unchecked((long)0xfedcba0987654321));
writer.WriteDateTime(new DateTime(0x1112223334445556));
writer.WriteDecimal(102030405060.70m);
writer.WriteDouble(double.NaN);
writer.WriteSingle(float.NegativeInfinity);
AssertEx.Equal(new byte[]
{
0x44, 0x33, 0x22, 0x11,
0x66, 0x55,
0x77,
0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
0xff, 0xff, 0xff, 0xff,
0xfe, 0xff,
0xfd,
0x01,
0x00,
0x21, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE,
0x56, 0x55, 0x44, 0x34, 0x33, 0x22, 0x12, 0x11,
0x02, 0xD6, 0xE0, 0x9A, 0x94, 0x47, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x00, 0x00, 0x80, 0xFF
}, writer.ToArray());
}
示例11: WriteCorHeader
private static void WriteCorHeader(Stream peStream, CorHeader corHeader)
{
var writer = new BlobBuilder(CorHeaderSize);
writer.WriteUInt32(CorHeaderSize);
writer.WriteUInt16(corHeader.MajorRuntimeVersion);
writer.WriteUInt16(corHeader.MinorRuntimeVersion);
writer.WriteUInt32((uint)corHeader.MetadataDirectory.RelativeVirtualAddress);
writer.WriteUInt32((uint)corHeader.MetadataDirectory.Size);
writer.WriteUInt32((uint)corHeader.Flags);
writer.WriteUInt32((uint)corHeader.EntryPointTokenOrRelativeVirtualAddress);
writer.WriteUInt32((uint)(corHeader.ResourcesDirectory.Size == 0 ? 0 : corHeader.ResourcesDirectory.RelativeVirtualAddress)); // 28
writer.WriteUInt32((uint)corHeader.ResourcesDirectory.Size);
writer.WriteUInt32((uint)(corHeader.StrongNameSignatureDirectory.Size == 0 ? 0 : corHeader.StrongNameSignatureDirectory.RelativeVirtualAddress)); // 36
writer.WriteUInt32((uint)corHeader.StrongNameSignatureDirectory.Size);
writer.WriteUInt32((uint)corHeader.CodeManagerTableDirectory.RelativeVirtualAddress);
writer.WriteUInt32((uint)corHeader.CodeManagerTableDirectory.Size);
writer.WriteUInt32((uint)corHeader.VtableFixupsDirectory.RelativeVirtualAddress);
writer.WriteUInt32((uint)corHeader.VtableFixupsDirectory.Size);
writer.WriteUInt32((uint)corHeader.ExportAddressTableJumpsDirectory.RelativeVirtualAddress);
writer.WriteUInt32((uint)corHeader.ExportAddressTableJumpsDirectory.Size);
writer.WriteUInt64(0);
Debug.Assert(writer.Length == CorHeaderSize);
Debug.Assert(writer.Length % 4 == 0);
writer.WriteTo(peStream);
}
示例12: WriteNameTable
private static void WriteNameTable(Stream peStream)
{
var writer = new BlobBuilder(SizeOfNameTable);
foreach (char ch in CorEntryPointDll)
{
writer.WriteByte((byte)ch);
}
writer.WriteByte(0);
writer.WriteUInt16(0);
Debug.Assert(writer.Length == SizeOfNameTable);
writer.WriteTo(peStream);
}
示例13: WriteImportTable
private void WriteImportTable(Stream peStream, int importTableRva, int importAddressTableRva)
{
var writer = new BlobBuilder(SizeOfImportTable);
int ilRVA = importTableRva + 40;
int hintRva = ilRVA + (_is32bit ? 12 : 16);
int nameRva = hintRva + 12 + 2;
// Import table
writer.WriteUInt32((uint)ilRVA); // 4
writer.WriteUInt32(0); // 8
writer.WriteUInt32(0); // 12
writer.WriteUInt32((uint)nameRva); // 16
writer.WriteUInt32((uint)importAddressTableRva); // 20
writer.WriteBytes(0, 20); // 40
// Import Lookup table
if (_is32bit)
{
writer.WriteUInt32((uint)hintRva); // 44
writer.WriteUInt32(0); // 48
writer.WriteUInt32(0); // 52
}
else
{
writer.WriteUInt64((uint)hintRva); // 48
writer.WriteUInt64(0); // 56
}
// Hint table
writer.WriteUInt16(0); // Hint 54|58
foreach (char ch in CorEntryPointName)
{
writer.WriteByte((byte)ch); // 65|69
}
writer.WriteByte(0); // 66|70
Debug.Assert(writer.Length == SizeOfImportTable);
writer.WriteTo(peStream);
}
示例14: WriteImportAddressTable
private void WriteImportAddressTable(Stream peStream, int importTableRva)
{
var writer = new BlobBuilder(SizeOfImportAddressTable);
int ilRVA = importTableRva + 40;
int hintRva = ilRVA + (_is32bit ? 12 : 16);
// Import Address Table
if (_is32bit)
{
writer.WriteUInt32((uint)hintRva); // 4
writer.WriteUInt32(0); // 8
}
else
{
writer.WriteUInt64((uint)hintRva); // 8
writer.WriteUInt64(0); // 16
}
Debug.Assert(writer.Length == SizeOfImportAddressTable);
writer.WriteTo(peStream);
}
示例15: WriteBytes2
public void WriteBytes2()
{
var writer = new BlobBuilder(4);
writer.WriteBytes(0xff, 0);
writer.WriteBytes(1, 4);
writer.WriteBytes(0xff, 0);
writer.WriteBytes(2, 10);
writer.WriteBytes(0xff, 0);
writer.WriteBytes(3, 1);
AssertEx.Equal(new byte[]
{
0x01, 0x01, 0x01, 0x01,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x03
}, writer.ToArray());
}