本文整理汇总了C#中MetadataBuilder.GetSerializedMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataBuilder.GetSerializedMetadata方法的具体用法?C# MetadataBuilder.GetSerializedMetadata怎么用?C# MetadataBuilder.GetSerializedMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MetadataBuilder
的用法示例。
在下文中一共展示了MetadataBuilder.GetSerializedMetadata方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Heaps_Reserve
public void Heaps_Reserve()
{
var mdBuilder = new MetadataBuilder();
var guid = mdBuilder.ReserveGuid();
var us = mdBuilder.ReserveUserString(3);
Assert.Equal(MetadataTokens.GuidHandle(1), guid.Handle);
Assert.Equal(MetadataTokens.UserStringHandle(1), us.Handle);
var serialized = mdBuilder.GetSerializedMetadata(MetadataRootBuilder.EmptyRowCounts, 12, isStandaloneDebugMetadata: false);
var builder = new BlobBuilder();
mdBuilder.WriteHeapsTo(builder, serialized.StringHeap);
AssertEx.Equal(new byte[]
{
// #String
0x00, 0x00, 0x00, 0x00,
// #US
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// #Guid
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// #Blob
0x00, 0x00, 0x00, 0x00
}, builder.ToArray());
guid.CreateWriter().WriteGuid(new Guid("D39F3559-476A-4D1E-B6D2-88E66395230B"));
us.CreateWriter().WriteUserString("bar");
AssertEx.Equal(new byte[]
{
// #String
0x00, 0x00, 0x00, 0x00,
// #US
0x00, 0x07, 0x62, 0x00, 0x61, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00,
// #Guid
0x59, 0x35, 0x9F, 0xD3, 0x6A, 0x47, 0x1E, 0x4D, 0xB6, 0xD2, 0x88, 0xE6, 0x63, 0x95, 0x23, 0x0B,
// #Blob
0x00, 0x00, 0x00, 0x00
}, builder.ToArray());
}
示例2: GetOrAddDocumentName1
public void GetOrAddDocumentName1()
{
var mdBuilder = new MetadataBuilder();
mdBuilder.GetOrAddDocumentName("");
mdBuilder.GetOrAddDocumentName("/a/b/c");
mdBuilder.GetOrAddDocumentName(@"\a\b\cc");
mdBuilder.GetOrAddDocumentName(@"/a/b\c");
mdBuilder.GetOrAddDocumentName(@"/\a/\b\\//c");
mdBuilder.GetOrAddDocumentName(@"a/");
mdBuilder.GetOrAddDocumentName(@"/");
mdBuilder.GetOrAddDocumentName(@"\\");
mdBuilder.GetOrAddDocumentName("\ud800"); // unpaired surrogate
mdBuilder.GetOrAddDocumentName("\0");
var serialized = mdBuilder.GetSerializedMetadata(MetadataRootBuilder.EmptyRowCounts, 12, isStandaloneDebugMetadata: false);
var heaps = new BlobBuilder();
mdBuilder.WriteHeapsTo(heaps, serialized.StringHeap);
AssertEx.Equal(new byte[]
{
// #String
0x00, 0x00, 0x00, 0x00,
// #US
0x00, 0x00, 0x00, 0x00,
0x00, // 0x00
// ""
0x02, (byte)'/', 0x00,
0x01, (byte)'a', // 0x04
0x01, (byte)'b', // 0x06
0x01, (byte)'c', // 0x08
// "/a/b/c"
0x05, (byte)'/', 0x00, 0x04, 0x06, 0x08,
// 0x10
0x02, (byte)'c', (byte)'c',
// @"\a\b\cc"
0x05, (byte)'\\', 0x00, 0x04, 0x06, 0x10,
// 0x19
0x03, (byte)'b', (byte)'\\', (byte)'c',
// @"/a/b\c"
0x04, (byte)'/', 0x00, 0x04, 0x19,
// 0x22
0x02, (byte)'\\', (byte)'a',
// 0x25
0x04, (byte)'\\', (byte)'b', (byte)'\\', (byte)'\\',
// @"/\a/\b\\//c"
0x06, (byte)'/', 0x00, 0x22, 0x25, 0x00, 0x08,
// @"a/"
0x03, (byte)'/', 0x04, 0x00,
// @"/"
0x03, (byte)'/', 0x00, 0x00,
// @"\\"
0x04, (byte)'\\', 0x00, 0x00, 0x00,
// 0x3E
0x03, 0xED, 0xA0, 0x80,
// "\ud800"
0x02, (byte)'/', 0x3E,
// 0x45
0x01, 0x00,
// "\0"
0x02, (byte)'/', 0x45,
// heap padding
0x00, 0x00
}, heaps.ToArray());
}
示例3: Heaps_StartOffsets
public void Heaps_StartOffsets()
{
var mdBuilder = new MetadataBuilder(
userStringHeapStartOffset: 0x10,
stringHeapStartOffset: 0x20,
blobHeapStartOffset: 0x30,
guidHeapStartOffset: 0x40);
var g = mdBuilder.GetOrAddGuid(new Guid("D39F3559-476A-4D1E-B6D2-88E66395230B"));
Assert.Equal(5, g.Index);
var s0 = mdBuilder.GetOrAddString("");
Assert.False(s0.IsVirtual);
Assert.Equal(0, s0.GetWriterVirtualIndex());
var s1 = mdBuilder.GetOrAddString("foo");
Assert.True(s1.IsVirtual);
Assert.Equal(1, s1.GetWriterVirtualIndex());
var us0 = mdBuilder.GetOrAddUserString("");
Assert.Equal(0x11, us0.GetHeapOffset());
var us1 = mdBuilder.GetOrAddUserString("bar");
Assert.Equal(0x13, us1.GetHeapOffset());
var b0 = mdBuilder.GetOrAddBlob(new byte[0]);
Assert.Equal(0, b0.GetHeapOffset());
var b1 = mdBuilder.GetOrAddBlob(new byte[] { 1, 2 });
Assert.Equal(0x31, b1.GetHeapOffset());
var serialized = mdBuilder.GetSerializedMetadata(MetadataRootBuilder.EmptyRowCounts, 12, isStandaloneDebugMetadata: false);
Assert.Equal(5, mdBuilder.SerializeHandle(g));
Assert.Equal(0, mdBuilder.SerializeHandle(serialized.StringMap, s0));
Assert.Equal(0x21, mdBuilder.SerializeHandle(serialized.StringMap, s1));
Assert.Equal(0x11, mdBuilder.SerializeHandle(us0));
Assert.Equal(0x13, mdBuilder.SerializeHandle(us1));
Assert.Equal(0, mdBuilder.SerializeHandle(b0));
Assert.Equal(0x31, mdBuilder.SerializeHandle(b1));
var heaps = new BlobBuilder();
mdBuilder.WriteHeapsTo(heaps, serialized.StringHeap);
AssertEx.Equal(new byte[]
{
// #String
0x00,
0x66, 0x6F, 0x6F, 0x00,
0x00, 0x00, 0x00,
// #US
0x00,
0x01, 0x00,
0x07, 0x62, 0x00, 0x61, 0x00, 0x72, 0x00, 0x00,
0x00,
// #Guid
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x59, 0x35, 0x9F, 0xD3, 0x6A, 0x47, 0x1E, 0x4D, 0xB6, 0xD2, 0x88, 0xE6, 0x63, 0x95, 0x23, 0x0B,
// #Blob
0x00, 0x02, 0x01, 0x02
}, heaps.ToArray());
Assert.Throws<ArgumentNullException>(() => mdBuilder.GetOrAddString(null));
}
示例4: Heaps_Empty
public void Heaps_Empty()
{
var mdBuilder = new MetadataBuilder();
var serialized = mdBuilder.GetSerializedMetadata(MetadataRootBuilder.EmptyRowCounts, 12, isStandaloneDebugMetadata: false);
var builder = new BlobBuilder();
mdBuilder.WriteHeapsTo(builder, serialized.StringHeap);
AssertEx.Equal(new byte[]
{
0x00, 0x00, 0x00, 0x00, // #String
0x00, 0x00, 0x00, 0x00, // #US
// #Guid
0x00, 0x00, 0x00, 0x00 // #Blob
}, builder.ToArray());
}