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


C# MetadataReader.GetString方法代码示例

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


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

示例1: ValidateEvent

        /// <summary>
        /// EventMap Table Columns:
        ///     Parent (RID to TypeDef)
        ///     EventList (RID to EventTable)
        /// ===========================================
        /// Event Table Columns:
        ///     Name (offset to #String)
        ///     Flags (2 byte unsigned)
        ///     EventType (token to TypeDefOrRef)
        /// </summary>
        private void ValidateEvent(MetadataReader reader, uint rowId, uint startIdx, uint count, bool isVBMod = false)
        {
            if (0 == count)
            {
                return;
            }

            var expNames = new string[] { "E01", "E01", "CS1IGoo<System.Linq.Expressions.Expression,System.Object>.E01" };

            // ModuleVB01
            // Map: 0:TypeDef[2000003], 1:Event[14000001]
            // Event: 0:0000, 1:string#1c6, 2:TypeDefOrRef[02000006]
            var modNames = new string[] { "AnEvent" };
            var modTokens = new uint[] { 0x02000006 };

            uint zeroBased = startIdx - 1;
            uint delta = count;

            // Last one
            if (0xF0000000 == count)
            {
                delta = (uint)reader.EventTable.NumberOfRows - zeroBased;
                if (0 == delta)
                {
                    return;
                }
            }

            // Validity Rules
            Assert.InRange((uint)reader.EventTable.NumberOfRows, zeroBased + count, uint.MaxValue);
            for (uint i = zeroBased; i < zeroBased + count; i++)
            {
                var handle = EventDefinitionHandle.FromRowId((int)i + 1);
                var evnt = reader.GetEventDefinition(handle);

                // Name
                if (isVBMod)
                {
                    Assert.Equal(modNames[i], reader.GetString(evnt.Name));
                }
                else
                {
                    Assert.Equal(expNames[i], reader.GetString(evnt.Name));
                }

                Assert.Equal(0, (ushort)evnt.Attributes);
                if (isVBMod)
                {
                    Assert.Equal(modTokens[i], (uint)evnt.Type.Token);
                }
                else
                {
                    Assert.Equal((int)rowId, evnt.Type.RowId); // could be TypeSpec Id if it's in generic
                }
            }
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:66,代码来源:MetadataReaderTests.cs

示例2: ValidateNamespaceChildren

        /// <summary>
        /// Helper method that will validate that a NamespaceDefinition (and all NamespaceDefinitions considered children
        /// of it) report correct values for their child namespaces, types, etc. All namespaces in the module are expected
        /// to be listed in the allNamespaces array. Additionally, the global namespace is expected to have type definitions
        /// for GlobalClassA, GlobalClassB, and Module. No type forwarder declarations are expected.
        /// 
        /// All namespaces that aren't the global NS are expected to have type definitions equal to the array
        /// @namespaceName.Split('.')
        /// So, ns1.Ns2.NS3 is expected to have type definitions
        /// {"ns1", "Ns2", "NS3"}.
        /// 
        /// definitionExceptions and forwarderExceptions may be used to override the default expectations. Pass in 
        /// namespace (key) and what is expected (list of strings) for each exception.
        /// </summary>
        private void ValidateNamespaceChildren(
            MetadataReader reader,
            NamespaceDefinitionHandle initHandle,
            string[] allNamespaces,
            IReadOnlyDictionary<string, IList<string>> definitionExceptions = null,
            IReadOnlyDictionary<string, IList<string>> forwarderExceptions = null)
        {
            // Don't want to have to deal with null.
            if (definitionExceptions == null)
            {
                definitionExceptions = new Dictionary<string, IList<string>>();
            }

            if (forwarderExceptions == null)
            {
                forwarderExceptions = new Dictionary<string, IList<string>>();
            }

            var rootNamespaceDefinition = reader.GetNamespaceDefinition(initHandle);
            string rootNamespaceName = reader.GetString(initHandle);

            // We need to be in the table of all namespaces...
            Assert.Contains(rootNamespaceName, allNamespaces);

            // Cool. Now check to make sure that .Name only returns the last bit of our namespace name.
            var expNamespaceNameSegment = rootNamespaceName.Split('.').Last();
            var rootNamespaceNameSegment = reader.GetString(rootNamespaceDefinition.Name);
            Assert.Equal(expNamespaceNameSegment, rootNamespaceNameSegment);

            bool isGlobalNamespace = rootNamespaceName.Length == 0;
            string[] expTypeDefinitions = null;
            // Special case: Global NS has GlobalClassA, GlobalClassB. Others just have autogenerated classes.
            if (definitionExceptions.ContainsKey(rootNamespaceName))
            {
                expTypeDefinitions = definitionExceptions[rootNamespaceName].ToArray();
            }
            else if (isGlobalNamespace)
            {
                expTypeDefinitions = new[] { "GlobalClassA", "GlobalClassB", "<Module>" };
            }
            else
            {
                expTypeDefinitions = rootNamespaceName.Split('.');
            }

            // Validating type definitions inside the namespace...
            int numberOfTypeDefinitions = 0;
            foreach (var definitionHandle in rootNamespaceDefinition.TypeDefinitions)
            {
                var definition = reader.GetTypeDefinition(definitionHandle);
                var definitionName = reader.GetString(definition.Name);
                var definitionFullNamespaceName = reader.GetString(definition.Namespace);
                Assert.Equal(rootNamespaceName, definitionFullNamespaceName);
                Assert.Contains(definitionName, expTypeDefinitions);
                numberOfTypeDefinitions += 1;
            }

            // Guarantee that there are no extra unexpected members...
            Assert.Equal(numberOfTypeDefinitions, expTypeDefinitions.Length);

            string[] expTypeForwarders = null;
            if (forwarderExceptions.ContainsKey(rootNamespaceName))
            {
                expTypeForwarders = forwarderExceptions[rootNamespaceName].ToArray();
            }
            else
            {
                expTypeForwarders = new string[] { };
            }

            int numberOfTypeForwarders = 0;
            foreach (var forwarderHandle in rootNamespaceDefinition.ExportedTypes)
            {
                var forwarder = reader.GetExportedType(forwarderHandle);
                Assert.True(reader.StringComparer.Equals(forwarder.Namespace, rootNamespaceName));
                var forwarderName = reader.GetString(forwarder.Name);
                Assert.Contains(forwarderName, expTypeForwarders);
                numberOfTypeForwarders += 1;
            }
            Assert.Equal(expTypeForwarders.Length, numberOfTypeForwarders);

            // Validate sub-namespaces

            // If the last index of '.' in a namespace name is == the current name's length, then
            // that ns is a direct child of the current one!
            IList<String> expChildren = null;
//.........这里部分代码省略.........
开发者ID:nnyamhon,项目名称:corefx,代码行数:101,代码来源:MetadataReaderTests.cs

示例3: ValidateProperty

        /// <summary>
        /// PropertyMap Table Columns:
        ///     Parent (RID to TypeDef)
        ///     PropertyList (RID to EventTable)
        /// ===========================================
        /// Property Table Columns:
        ///     Name (offset to #String)
        ///     PropFlags (2 byte unsigned)
        ///     Type (offset to #blob - Signature)
        /// </summary>
        private void ValidateProperty(MetadataReader reader, uint rowId, uint startIndex, uint count, bool isVBMod = false)
        {
            if (0 == count)
            {
                return;
            }

            // ModuleCS01
            var expNames = new string[]
            {
                "AppProp", "P01", "Item", "P01", "Item",
                "CS1IGoo<System.Linq.Expressions.Expression,System.Object>.P01",
                "CS1IGoo<System.Linq.Expressions.Expression,System.Object>.Item",
            };
            var expSigs = new byte[][]
            {
                new byte[] { 0x28, 00, 0x15, 0x12, 0x21, 0x02, 0x12, 0x19, 0x1c }, new byte[] { 0x28, 00, 0x13, 00 },
                new byte[] { 0x28, 01, 0x1c, 0x13, 00 }, new byte[] { 0x28, 0x00, 0x13, 00 }, new byte[] { 0x28, 0x01, 0x1c, 0x13, 00 },
                new byte[] { 0x28, 00, 0x12, 0x19 }, new byte[] { 0x28, 01, 0x1c, 0x12, 0x19 }
            };

            // ModuleVB01
            // Prop: 0:0000, 1:string#13c, 2:blob#70 | 0:0000, 1:string#14d, 2:blob#75
            var modNames = new string[]
            {
                "ModVBDefaultProp", "ModVBProp",
            };
            var modSigs = new byte[][]
            {
                new byte[] { 0x28, 01, 0x0e, 0x08 }, new byte[] { 0x28, 00, 0x11, 0x09 },
            };

            // Validity Rules
            uint zeroBased = startIndex - 1;
            uint delta = count;

            // Last one
            if (0xF0000000 == count)
            {
                delta = (uint)reader.PropertyTable.NumberOfRows - zeroBased;
                if (0 == delta)
                {
                    return;
                }
            }

            Assert.InRange((uint)reader.PropertyTable.NumberOfRows, zeroBased + count, uint.MaxValue);
            for (uint i = zeroBased; i < zeroBased + count; i++)
            {
                var handle = PropertyDefinitionHandle.FromRowId((int)i + 1);
                var row = reader.GetPropertyDefinition(handle);

                // Name
                if (isVBMod)
                {
                    Assert.Equal(modNames[i], reader.GetString(row.Name));
                }
                else
                {
                    Assert.Equal(expNames[i], reader.GetString(row.Name));
                }

                Assert.Equal(0, (ushort)row.Attributes);

                var sig = reader.GetBlobBytes(row.Signature);
                Assert.Equal(40, sig[0]);
                byte[] exp;
                if (isVBMod)
                {
                    exp = modSigs[i];
                }
                else
                {
                    exp = expSigs[i];
                }

                for (int j = 0; j < exp.Length; j++)
                {
                    Assert.Equal(exp[j], sig[j]);
                }
            } // for
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:92,代码来源:MetadataReaderTests.cs

示例4: ValidateParam

        /// <summary>
        /// Param Table Columns:
        ///     Name (offset to #String)
        ///     Flags, Sequence (2 byte unsigned)
        /// </summary>
        private void ValidateParam(MetadataReader reader, uint startIndex, uint count, bool isMod = false)
        {
            if (count == 0)
            {
                return;
            }

            // AppCS - 7
            var expNames = new string[] { "p", "t", "p", "value", "t", "value", "t" };

            // =================
            // ModuleVB01 - 20
            var modNames = new string[]
            {
                "index", "index", "value", "em", "cls",    "del", "obj", "obj", "o", "e",
                "p", "TargetObject", "TargetMethod", "o", "e",
                "DelegateCallback", "DelegateAsyncState", "DelegateAsyncResult", "o", "e",
            };
            var modFlags = new ushort[] { 0, 0, 0, 0, 0x1010, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
            var modSeqs = new ushort[] { 1, 1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 4, 1, 1, 2, };

            if (startIndex > reader.ParamTable.NumberOfRows)
            {
                return;
            }

            uint zeroBased = startIndex - 1;
            uint delta = count;

            // Last one
            if (0xF0000000 == count)
            {
                delta = (uint)reader.ParamTable.NumberOfRows - zeroBased;
                if (0 == delta)
                {
                    return;
                }
            }

            Assert.InRange((uint)reader.ParamTable.NumberOfRows, zeroBased + delta, uint.MaxValue); // 1 based
            for (uint i = zeroBased; i < zeroBased + delta; i++)
            {
                var handle = ParameterHandle.FromRowId((int)i + 1);
                var row = reader.GetParameter(handle);

                // Console.WriteLine("P: {0}", GetStringData(row.Name));
                if (isMod)
                {
                    Assert.Equal(modNames[i], reader.GetString(row.Name));
                    Assert.Equal(modFlags[i], (ushort)row.Attributes);
                    Assert.Equal(modSeqs[i], row.SequenceNumber);
                }
                else
                {
                    Assert.Equal(expNames[i], reader.GetString(row.Name));
                    Assert.Equal((ushort)0, (ushort)row.Attributes);
                    Assert.Equal((ushort)1, row.SequenceNumber);
                }
            } // for
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:65,代码来源:MetadataReaderTests.cs

示例5: ValidateMethodDef


//.........这里部分代码省略.........
            {
                new byte[] { 0x20, 0x00, 0x01 }, new byte[] { 0x20, 01, 0x0e, 0x08 },
                new byte[] { 0x20, 02, 01, 0x08, 0x0e }, new byte[] { 0x20, 00, 0x11, 0x09 },
                new byte[] { 0x20, 02, 01, 0x11, 0x0d, 0x12, 0x11 }, new byte[] { 0x20, 01, 0x12, 0x15, 0x10, 0x12, 0x19 },
                new byte[] { 0x00, 00, 01 }, new byte[] { 0x20, 01, 01, 0x12, 0x18 },
                new byte[] { 0x20, 01, 01, 0x12, 0x18 }, new byte[] { 0x20, 02, 01, 0x1c, 0x12, 0x21 },
                new byte[] { 0x20, 01, 0x1c, 0x10, 0x11, 0x14 }, new byte[] { 0x20, 02, 01, 0x1c, 0x18 },
                new byte[] { 0x20, 04, 0x12, 0x2d, 0x1c, 0x12, 0x21, 0x12, 0x31, 0x1c }, new byte[] { 0x20, 01, 01, 0x12, 0x2d },
                new byte[] { 0x20, 02, 01, 0x1c, 0x12, 0x21 },
            };

            if (startIndex > reader.MethodDefTable.NumberOfRows)
            {
                return;
            }

            uint zeroBased = startIndex - 1;
            uint delta = count;

            // Last one
            if (0xF0000000 == count)
            {
                delta = (uint)reader.MethodDefTable.NumberOfRows - zeroBased;
                if (0 == delta)
                {
                    return;
                }
            }

            Assert.InRange((uint)reader.MethodDefTable.NumberOfRows, zeroBased + delta, uint.MaxValue); // 1 based
            bool first = true;
            uint prevParamStart = 0;
            for (uint i = zeroBased; i < zeroBased + delta; i++)
            {
                var handle = MethodDefinitionHandle.FromRowId((int)i + 1);
                var flags = reader.MethodDefTable.GetFlags(handle);
                var implFlags = reader.MethodDefTable.GetImplFlags(handle);
                var rva = reader.MethodDefTable.GetRva(handle);
                var name = reader.MethodDefTable.GetName(handle);
                var signature = reader.MethodDefTable.GetSignature(handle);
                var paramStart = (uint)reader.MethodDefTable.GetParamStart((int)i + 1);

                if (isMod)
                {
                    // Console.WriteLine("M: {0}", reader.GetString(row.Name));
                    Assert.Equal(modNames[i], reader.GetString(name));

                    Assert.Equal(modFlags[i], (ushort)flags);
                    Assert.Equal(modImpls[i], (ushort)implFlags);
                    Assert.Equal(modRVAs[i], (uint)rva);
                }
                else
                {
                    // Console.WriteLine("M: {0}", reader.GetString(row.Name));
                    Assert.Equal(expNames[i], reader.GetString(name));

                    Assert.Equal(expFlags[i], (ushort)flags);
                    Assert.Equal((ushort)0, (ushort)implFlags);
                    Assert.Equal(expRVAs[i], (uint)rva);
                }

                var sig = reader.GetBlobBytes(signature);
                int len = 0;
                if (isMod)
                {
                    len = modSigs[i].Length;
                }
                else
                {
                    len = expSigs[i].Length;
                }

                for (int j = 0; j < len; j++)
                {
                    if (isMod)
                    {
                        Assert.Equal(modSigs[i][j], sig[j]);
                    }
                    else
                    {
                        Assert.Equal(expSigs[i][j], sig[j]);
                    }
                }

                // validate previous row's param as it needs current row's other to calc how many
                if (!first)
                {
                    ValidateParam(reader, prevParamStart, paramStart - prevParamStart, isMod);
                }

                // Last
                if (i + 1 == reader.MethodDefTable.NumberOfRows)
                {
                    ValidateParam(reader, paramStart, 0xF0000000, isMod);
                }

                prevParamStart = paramStart;
                first = false;
            }
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:101,代码来源:MetadataReaderTests.cs

示例6: ValidateFieldDef

        /// <summary>
        /// Field Table Columns:
        ///     Name (offset to #String)
        ///     Flags (2 byte unsigned)
        ///     Signature (offset to #blob)
        /// </summary>
        private void ValidateFieldDef(MetadataReader reader, uint startIndex, uint count, bool isMod = false)
        {
            if (count == 0)
            {
                return;
            }

            // APPCS
            var expNames = new string[] { "AppField01", "AppField02" };
            var expFlags = new FieldAttributes[]
            {
                /*0x11*/
                         FieldAttributes.Private | FieldAttributes.Static,
                /*0x01*/ FieldAttributes.Private,
                };
            var expSigs = new byte[][] { new byte[] { 0x06, 0x12, 0x11 }, new byte[] { 0x06, 0x12, 0x25 }, };

            // =====================================================================================================
            // VB Module - 8
            var modNames = new string[] { "ConstString", "ArrayField", "AnEventEvent", "value__", "None", "Red", "Yellow", "Blue", };
            var modFlags = new FieldAttributes[]
            {
                /* 0x8053 */
                             FieldAttributes.HasDefault | FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.FamANDAssem | FieldAttributes.Private,
                /* 0x0016 */ FieldAttributes.Static | FieldAttributes.Family | FieldAttributes.FamANDAssem,
                /* 0x0001 */ FieldAttributes.Private,
                /* 0x0606 */ FieldAttributes.RTSpecialName | FieldAttributes.SpecialName | FieldAttributes.Family | FieldAttributes.FamANDAssem,
                /* 0x8056 */ FieldAttributes.HasDefault | FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.Family | FieldAttributes.FamANDAssem,
                /* 0x8056 */ FieldAttributes.HasDefault | FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.Family | FieldAttributes.FamANDAssem,
                /* 0x8056 */ FieldAttributes.HasDefault | FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.Family | FieldAttributes.FamANDAssem,
                /* 0x8056 */ FieldAttributes.HasDefault | FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.Family | FieldAttributes.FamANDAssem,
                };
            var modSigs = new byte[][]
            {
                new byte[] { 0x06, 0x0e }, new byte[] { 0x06, 0x14, 0x11, 0x14, 02, 00, 02, 00, 00 },
                new byte[] { 0x06, 0x12, 0x18 }, new byte[] { 0x06, 0x08 },
                new byte[] { 0x06, 0x11, 0x10 }, new byte[] { 0x06, 0x11, 0x10 },
                new byte[] { 0x06, 0x11, 0x10 }, new byte[] { 0x06, 0x11, 0x10 },
            };

            if (startIndex > reader.FieldTable.NumberOfRows)
            {
                return;
            }

            uint zeroBased = startIndex - 1;
            uint delta = count;

            // Last one
            if (0xF0000000 == count)
            {
                delta = (uint)reader.FieldTable.NumberOfRows - zeroBased;
                if (0 == delta)
                {
                    return;
                }
            }

            Assert.InRange((uint)reader.FieldTable.NumberOfRows, zeroBased + delta, uint.MaxValue); // 1 based
            for (uint i = zeroBased; i < zeroBased + delta; i++)
            {
                var handle = FieldDefinitionHandle.FromRowId((int)(i + 1));
                var row = reader.GetFieldDefinition(handle);

                if (isMod)
                {
                    Assert.Equal(modNames[i], reader.GetString(row.Name));
                    Assert.Equal(modFlags[i], row.Attributes);
                }
                else
                {
                    Assert.Equal(expNames[i], reader.GetString(row.Name));
                    Assert.Equal(expFlags[i], row.Attributes);
                }

                var sig = reader.GetBlobBytes(row.Signature);

                // calling convention, always 6 for field
                Assert.Equal(sig[0], 6);
                int len = 0;
                if (isMod)
                {
                    len = modSigs[i].Length;
                }
                else
                {
                    len = expSigs[i].Length;
                }

                for (int j = 1; j < len; j++)
                {
                    if (isMod)
                    {
                        Assert.Equal(modSigs[i][j], sig[j]);
//.........这里部分代码省略.........
开发者ID:nnyamhon,项目名称:corefx,代码行数:101,代码来源:MetadataReaderTests.cs

示例7: GetString

 private static string GetString(MetadataReader metadataReader, StringHandle handle)
 {
     return CilDecoderHelpers.Instance.NormalizeString(metadataReader.GetString(handle));
 }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:4,代码来源:CilDecoder.cs


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