本文整理汇总了C#中Microsoft.Cci.BlobBuilder.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.ToArray方法的具体用法?C# BlobBuilder.ToArray怎么用?C# BlobBuilder.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Cci.BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: WriteUTF16
public void WriteUTF16()
{
var writer = new BlobBuilder(4);
writer.WriteUTF16("");
writer.WriteUTF16("a");
writer.WriteUTF16("");
writer.WriteUTF16(new char[0]);
writer.WriteUTF16(new char[] { '\ud800' }); // hi surrogate
writer.WriteUTF16("\udc00"); // lo surrogate
writer.WriteUTF16("\ud800\udc00"); // pair
writer.WriteUTF16(new char[] { '\udc00', '\ud800' }); // lo + hi
writer.WriteUTF16("\u1234");
AssertEx.Equal(new byte[]
{
0x61, 0x00,
0x00, 0xD8,
0x00, 0xDC,
0x00, 0xD8, 0x00, 0xDC,
0x00, 0xDC, 0x00, 0xD8,
0x34, 0x12
}, writer.ToArray());
}
示例3: WriteAlignPad
public void WriteAlignPad()
{
var writer = new BlobBuilder(4);
writer.WriteByte(0x01);
writer.PadTo(2);
writer.WriteByte(0x02);
writer.Align(4);
writer.Align(4);
writer.WriteByte(0x03);
writer.Align(4);
writer.WriteByte(0x04);
writer.WriteByte(0x05);
writer.Align(8);
writer.WriteByte(0x06);
writer.Align(2);
writer.Align(1);
AssertEx.Equal(new byte[]
{
0x01, 0x00, 0x02, 0x00,
0x03, 0x00, 0x00, 0x00,
0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x06, 0x00
}, writer.ToArray());
}
示例4: 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());
}
示例5: WriteBytes1
public void WriteBytes1()
{
var writer = new BlobBuilder(4);
writer.WriteBytes(new byte[] { 1, 2, 3, 4 });
writer.WriteBytes(new byte[] { });
writer.WriteBytes(new byte[] { }, 0, 0);
writer.WriteBytes(new byte[] { 5, 6, 7, 8 });
writer.WriteBytes(new byte[] { 9 });
writer.WriteBytes(new byte[] { 0x0a }, 0, 0);
writer.WriteBytes(new byte[] { 0x0b }, 0, 1);
writer.WriteBytes(new byte[] { 0x0c }, 1, 0);
writer.WriteBytes(new byte[] { 0x0d, 0x0e }, 1, 1);
AssertEx.Equal(new byte[]
{
0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08,
0x09,
0x0b,
0x0e
}, writer.ToArray());
}
示例6: WritePrimitive
public void WritePrimitive()
{
var writer = new BlobBuilder(17);
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());
}
示例7: TestCompressedSignedInteger
private static void TestCompressedSignedInteger(byte[] expected, int value)
{
var writer = new BlobWriter(4);
writer.WriteCompressedSignedInteger(value);
AssertEx.Equal(expected, writer.ToArray());
var builder = new BlobBuilder();
builder.WriteCompressedSignedInteger(value);
AssertEx.Equal(expected, builder.ToArray());
}
示例8: CompressSignedInteger
private static byte[] CompressSignedInteger(int value)
{
var writer = new BlobBuilder();
writer.WriteCompressedSignedInteger(value);
return writer.ToArray();
}
示例9: Link
public void Link()
{
var builder1 = new BlobBuilder(16);
builder1.WriteByte(1);
var builder2 = new BlobBuilder(16);
builder2.WriteByte(2);
var builder3 = new BlobBuilder(16);
builder3.WriteByte(3);
var builder4 = new BlobBuilder(16);
builder4.WriteByte(4);
var builder5 = new BlobBuilder(16);
builder5.WriteByte(5);
builder2.LinkPrefix(builder1);
AssertEx.Equal(new byte[] { 1, 2 }, builder2.ToArray());
Assert.Throws<InvalidOperationException>(() => builder1.ToArray());
Assert.Throws<InvalidOperationException>(() => builder2.LinkPrefix(builder1));
Assert.Throws<InvalidOperationException>(() => builder1.WriteByte(0xff));
Assert.Throws<InvalidOperationException>(() => builder1.WriteBytes(1, 10));
Assert.Throws<InvalidOperationException>(() => builder1.WriteBytes(new byte[] { 1 }));
Assert.Throws<InvalidOperationException>(() => builder1.ReserveBytes(1));
Assert.Throws<InvalidOperationException>(() => builder1.GetBlobs());
Assert.Throws<InvalidOperationException>(() => builder1.ContentEquals(builder1));
Assert.Throws<InvalidOperationException>(() => builder1.WriteUTF16("str"));
Assert.Throws<InvalidOperationException>(() => builder1.WriteUTF8("str", allowUnpairedSurrogates: false));
builder2.LinkSuffix(builder3);
AssertEx.Equal(new byte[] { 1, 2, 3 }, builder2.ToArray());
Assert.Throws<InvalidOperationException>(() => builder3.LinkPrefix(builder5));
builder2.LinkPrefix(builder4);
AssertEx.Equal(new byte[] { 4, 1, 2, 3 }, builder2.ToArray());
Assert.Throws<InvalidOperationException>(() => builder4.LinkPrefix(builder5));
builder2.LinkSuffix(builder5);
AssertEx.Equal(new byte[] { 4, 1, 2, 3, 5 }, builder2.ToArray());
}
示例10: LinkPrefix1
public void LinkPrefix1()
{
var builder1 = new BlobBuilder(16);
builder1.WriteByte(1);
builder1.WriteByte(2);
builder1.WriteByte(3);
var builder2 = new BlobBuilder(16);
builder2.WriteByte(4);
builder1.LinkPrefix(builder2);
AssertEx.Equal(new byte[] { 4, 1, 2, 3 }, builder1.ToArray());
}
示例11: WriteContentToBlobBuilder
public void WriteContentToBlobBuilder()
{
var builder1 = new BlobBuilder(16);
for (int i = 0; i < 20; i++)
{
builder1.WriteByte((byte)i);
}
var builder2 = new BlobBuilder(256);
builder1.WriteContentTo(builder2);
AssertEx.Equal(new byte[]
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13
}, builder2.ToArray());
builder1.WriteByte(0xff);
builder1.WriteContentTo(builder2);
AssertEx.Equal(new byte[]
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13,
0xff,
}, builder2.ToArray());
}
示例12: ToImmutableArray
public void ToImmutableArray()
{
var builder = new BlobBuilder(16);
AssertEx.Equal(new byte[] { }, builder.ToArray(0, 0));
for (int i = 0; i < 13; i++)
{
builder.WriteByte((byte)i);
}
builder.WriteUInt32(0xaabbccdd);
AssertEx.Equal(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0xDD, 0xCC, 0xBB, 0xAA }, builder.ToImmutableArray());
AssertEx.Equal(new byte[] { }, builder.ToImmutableArray(0, 0));
AssertEx.Equal(new byte[] { 0 }, builder.ToImmutableArray(0, 1));
AssertEx.Equal(new byte[] { 1 }, builder.ToImmutableArray(1, 1));
AssertEx.Equal(new byte[] { }, builder.ToImmutableArray(14, 0));
AssertEx.Equal(new byte[] { }, builder.ToImmutableArray(15, 0));
AssertEx.Equal(new byte[] { }, builder.ToImmutableArray(16, 0));
AssertEx.Equal(new byte[] { }, builder.ToImmutableArray(17, 0));
AssertEx.Equal(new byte[] { 0xdd }, builder.ToImmutableArray(13, 1));
AssertEx.Equal(new byte[] { 0xcc }, builder.ToImmutableArray(14, 1));
AssertEx.Equal(new byte[] { 0xbb }, builder.ToImmutableArray(15, 1));
AssertEx.Equal(new byte[] { 0xaa }, builder.ToImmutableArray(16, 1));
AssertEx.Equal(new byte[] { 0xdd, 0xcc }, builder.ToImmutableArray(13, 2));
AssertEx.Equal(new byte[] { 0xcc, 0xbb }, builder.ToImmutableArray(14, 2));
AssertEx.Equal(new byte[] { 0xbb, 0xaa }, builder.ToImmutableArray(15, 2));
AssertEx.Equal(new byte[] { 0xdd, 0xcc, 0xbb }, builder.ToImmutableArray(13, 3));
AssertEx.Equal(new byte[] { 0xcc, 0xbb, 0xaa }, builder.ToImmutableArray(14, 3));
AssertEx.Equal(new byte[] { 0xdd, 0xcc, 0xbb, 0xaa }, builder.ToImmutableArray(13, 4));
}
示例13: ToArray_Errors
public void ToArray_Errors()
{
var builder = new BlobBuilder(16);
builder.WriteByte(1);
Assert.Throws<ArgumentOutOfRangeException>(() => builder.ToArray(-1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.ToArray(0, -1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.ToArray(0, 2));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.ToArray(1, 1));
}
示例14: ToArray2
public void ToArray2()
{
var builder = new BlobBuilder(16);
AssertEx.Equal(new byte[] { }, builder.ToArray(0, 0));
for (int i = 0; i < 34; i++)
{
builder.WriteByte((byte)i);
}
AssertEx.Equal(new byte[]
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21
}, builder.ToArray());
AssertEx.Equal(new byte[]
{
0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21
}, builder.ToArray(0x0e, 20));
AssertEx.Equal(new byte[] { 0x0E }, builder.ToArray(0x0e, 1));
AssertEx.Equal(new byte[] { 0x0E, 0x0F }, builder.ToArray(0x0e, 2));
AssertEx.Equal(new byte[] { 0x0E, 0x0F, 0x10 }, builder.ToArray(0x0e, 3));
AssertEx.Equal(new byte[] { 0x0E, 0x0F, 0x10, 0x11 }, builder.ToArray(0x0e, 4));
AssertEx.Equal(new byte[] { 0x1E }, builder.ToArray(0x1e, 1));
AssertEx.Equal(new byte[] { 0x1E, 0x1F }, builder.ToArray(0x1e, 2));
AssertEx.Equal(new byte[] { 0x1E, 0x1F, 0x20 }, builder.ToArray(0x1e, 3));
AssertEx.Equal(new byte[] { 0x1E, 0x1F, 0x20, 0x21 }, builder.ToArray(0x1e, 4));
}
示例15: WriteSerializedString
public void WriteSerializedString()
{
var writer = new BlobBuilder(4);
writer.WriteSerializedString("");
writer.WriteSerializedString("a");
writer.WriteSerializedString(null);
writer.WriteSerializedString("");
writer.WriteSerializedString("\ud800"); // hi surrogate
writer.WriteSerializedString("\udc00"); // lo surrogate
writer.WriteSerializedString("\ud800\udc00"); // pair
writer.WriteSerializedString("\udc00\ud800"); // lo + hi
writer.WriteSerializedString("\u1234");
AssertEx.Equal(new byte[]
{
0x00,
0x01, 0x61,
0xff,
0x00,
0x03, 0xED, 0xA0, 0x80,
0x03, 0xED, 0xB0, 0x80,
0x04, 0xF0, 0x90, 0x80, 0x80,
0x06, 0xED, 0xB0, 0x80, 0xED, 0xA0, 0x80,
0x03, 0xE1, 0x88, 0xB4
}, writer.ToArray());
}