当前位置: 首页>>代码示例>>C#>>正文


C# MetadataBuilder.GetOrAddDocumentName方法代码示例

本文整理汇总了C#中MetadataBuilder.GetOrAddDocumentName方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataBuilder.GetOrAddDocumentName方法的具体用法?C# MetadataBuilder.GetOrAddDocumentName怎么用?C# MetadataBuilder.GetOrAddDocumentName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MetadataBuilder的用法示例。


在下文中一共展示了MetadataBuilder.GetOrAddDocumentName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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());
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:84,代码来源:MetadataBuilderTests.cs

示例2: GetOrAddDocumentName2

        public void GetOrAddDocumentName2()
        {
            var mdBuilder = new MetadataBuilder();
            mdBuilder.AddModule(0, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));

            var n1 = mdBuilder.GetOrAddDocumentName("");
            var n2 = mdBuilder.GetOrAddDocumentName("/a/b/c");
            var n3 = mdBuilder.GetOrAddDocumentName(@"\a\b\cc");
            var n4 = mdBuilder.GetOrAddDocumentName(@"/a/b\c");
            var n5 = mdBuilder.GetOrAddDocumentName(@"/\a/\b\\//c");
            var n6 = mdBuilder.GetOrAddDocumentName(@"a/");
            var n7 = mdBuilder.GetOrAddDocumentName(@"/");
            var n8 = mdBuilder.GetOrAddDocumentName(@"\\");
            var n9 = mdBuilder.GetOrAddDocumentName("\ud800"); // unpaired surrogate
            var n10 = mdBuilder.GetOrAddDocumentName("\0");

            var root = new MetadataRootBuilder(mdBuilder);
            var rootBuilder = new BlobBuilder();
            root.Serialize(rootBuilder, 0, 0);
            var mdImage = rootBuilder.ToImmutableArray();

            using (var provider = MetadataReaderProvider.FromMetadataImage(mdImage))
            {
                var mdReader = provider.GetMetadataReader();
                Assert.Equal("", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n1))));
                Assert.Equal("/a/b/c", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n2))));
                Assert.Equal(@"\a\b\cc", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n3))));
                Assert.Equal(@"/a/b\c", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n4))));
                Assert.Equal(@"/\a/\b\\//c", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n5))));
                Assert.Equal(@"a/", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n6))));
                Assert.Equal(@"/", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n7))));
                Assert.Equal(@"\\", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n8))));
                Assert.Equal("\uFFFd\uFFFd", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n9))));
                Assert.Equal("\0", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n10))));
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:36,代码来源:MetadataBuilderTests.cs

示例3: GetOrAddErrors

 public void GetOrAddErrors()
 {
     var mdBuilder = new MetadataBuilder();
     Assert.Throws<ArgumentNullException>("value", () => mdBuilder.GetOrAddBlob((BlobBuilder)null));
     Assert.Throws<ArgumentNullException>("value", () => mdBuilder.GetOrAddBlob((byte[])null));
     Assert.Throws<ArgumentNullException>("value", () => mdBuilder.GetOrAddBlob(default(ImmutableArray<byte>)));
     Assert.Throws<ArgumentNullException>("value", () => mdBuilder.GetOrAddBlobUTF8(null));
     Assert.Throws<ArgumentNullException>("value", () => mdBuilder.GetOrAddBlobUTF16(null));
     Assert.Throws<ArgumentNullException>("value", () => mdBuilder.GetOrAddDocumentName(null));
     Assert.Throws<ArgumentNullException>("value", () => mdBuilder.GetOrAddString(null));
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:11,代码来源:MetadataBuilderTests.cs


注:本文中的MetadataBuilder.GetOrAddDocumentName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。