Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PdbFunction"/> class.
        /// </summary>
        /// <param name="pdbFile">Portable PDB file reader.</param>
        /// <param name="handle">Our metadata reader handle.</param>
        internal PdbFunction(PdbFile pdbFile, MethodDebugInformationHandle handle)
        {
            PdbFile = pdbFile;
            methodDebugInformationCache = SimpleCache.CreateStruct(() => pdbFile.Reader.GetMethodDebugInformation(handle));
            localScopesCache            = SimpleCache.CreateStruct(() =>
            {
                var localScopes         = pdbFile.Reader.GetLocalScopes(handle);
                IPdbLocalScope[] scopes = new IPdbLocalScope[localScopes.Count];
                int i = 0;

                foreach (var l in localScopes)
                {
                    scopes[i++] = new PdbLocalScope(this, l);
                }
                return(scopes);
            });
            sequencePointsCache = SimpleCache.CreateStruct(() =>
            {
                var sequencePoints = MethodDebugInformation.GetSequencePoints();

                return(sequencePoints.Select(sp => new PdbSequencePoint(this, sp)).OfType <IPdbSequencePoint>().ToArray());
            });
            Token = System.Reflection.Metadata.Ecma335.MetadataTokens.GetToken(handle.ToDefinitionHandle());
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PdbLocalVariable"/> class.
 /// </summary>
 /// <param name="localScope">Local scope where this variable is defined.</param>
 /// <param name="handle">Our metadata reader handle.</param>
 public PdbLocalVariable(PdbLocalScope localScope, LocalVariableHandle handle)
 {
     LocalScope         = localScope;
     localVariableCache = SimpleCache.CreateStruct(() => LocalScope.Function.PdbFile.Reader.GetLocalVariable(handle));
     nameCache          = SimpleCache.CreateStruct(() => LocalScope.Function.PdbFile.Reader.GetString(LocalVariable.Name));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="PdbLocalConstant"/> class.
        /// </summary>
        /// <param name="localScope">Local scope where this contanst is defined.</param>
        /// <param name="handle">Our metadata reader handle.</param>
        internal PdbLocalConstant(PdbLocalScope localScope, LocalConstantHandle handle)
        {
            LocalScope         = localScope;
            localConstantCache = SimpleCache.CreateStruct(() => LocalScope.Function.PdbFile.Reader.GetLocalConstant(handle));
            nameCache          = SimpleCache.CreateStruct(() => LocalScope.Function.PdbFile.Reader.GetString(LocalConstant.Name));
            valueCache         = SimpleCache.CreateStruct <object>(() =>
            {
                var reader = LocalScope.Function.PdbFile.Reader.GetBlobReader(LocalConstant.Signature);
                SignatureTypeCode typeCode;

                while (true)
                {
                    typeCode = reader.ReadSignatureTypeCode();
                    if (typeCode == SignatureTypeCode.OptionalModifier || typeCode == SignatureTypeCode.RequiredModifier)
                    {
                        reader.ReadCompressedInteger();
                    }
                    else
                    {
                        break;
                    }
                }

                switch (typeCode)
                {
                case SignatureTypeCode.Boolean:
                    return((short)(reader.ReadBoolean() ? 1 : 0));

                case SignatureTypeCode.Char:
                    return(reader.ReadChar());

                case SignatureTypeCode.SByte:
                    return(reader.ReadSByte());

                case SignatureTypeCode.Byte:
                    return(reader.ReadByte());

                case SignatureTypeCode.Int16:
                    return(reader.ReadInt16());

                case SignatureTypeCode.UInt16:
                    return(reader.ReadUInt16());

                case SignatureTypeCode.Int32:
                    return(reader.ReadInt32());

                case SignatureTypeCode.UInt32:
                    return(reader.ReadUInt32());

                case SignatureTypeCode.Int64:
                    return(reader.ReadInt64());

                case SignatureTypeCode.UInt64:
                    return(reader.ReadUInt64());

                case SignatureTypeCode.Single:
                    return(reader.ReadSingle());

                case SignatureTypeCode.Double:
                    return(reader.ReadDouble());

                case SignatureTypeCode.String:
                    if (reader.RemainingBytes == 1)
                    {
                        if (reader.ReadByte() != 0xFF)
                        {
                            throw new Exception("Unexpected string constant");
                        }
                        return(null);
                    }
                    if (reader.RemainingBytes % 2 != 0)
                    {
                        throw new Exception("Unexpected string constant");
                    }
                    return(reader.ReadUTF16(reader.RemainingBytes));

                case SignatureTypeCode.TypeHandle:
                case SignatureTypeCode.Object:
                default:
                    // We don't know how to parse value
                    return(null);
                }
            });
        }