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


C# BlobReader.TryReadCompressedInteger方法代码示例

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


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

示例1: DecodeType

 // cf. MetadataDecoder<>.DecodeTypeOrThrow.
 private TypeSignature DecodeType(ref BlobReader signatureReader, SignatureTypeCode typeCode)
 {
     switch (typeCode)
     {
         case SignatureTypeCode.TypeHandle:
             {
                 int typeArgumentOffset = 0;
                 return DecodeType(signatureReader.ReadTypeHandle(), ImmutableArray<TypeSignature>.Empty, ref typeArgumentOffset);
             }
         case SignatureTypeCode.Array:
             {
                 var elementType = DecodeModifiersAndType(ref signatureReader);
                 int rank;
                 int sizes;
                 signatureReader.TryReadCompressedInteger(out rank);
                 signatureReader.TryReadCompressedInteger(out sizes);
                 if (sizes != 0)
                 {
                     throw UnhandledMetadata();
                 }
                 return new ArrayTypeSignature(elementType, rank);
             }
         case SignatureTypeCode.SZArray:
             {
                 var elementType = DecodeModifiersAndType(ref signatureReader);
                 return new ArrayTypeSignature(elementType, 1);
             }
         case SignatureTypeCode.GenericTypeInstance:
             return DecodeGenericTypeInstance(ref signatureReader);
         case SignatureTypeCode.Pointer:
             {
                 var pointedAtType = DecodeModifiersAndType(ref signatureReader);
                 return new PointerTypeSignature(pointedAtType);
             }
         case SignatureTypeCode.GenericTypeParameter:
             return DecodeGenericTypeParameter(ref signatureReader, _allTypeParameters, _containingArity);
         case SignatureTypeCode.GenericMethodParameter:
             return DecodeGenericTypeParameter(ref signatureReader, _methodTypeParameters, 0);
         default:
             {
                 var signature = typeCode.ToSpecialType().GetTypeSignature();
                 if (signature == null)
                 {
                     throw UnhandledMetadata();
                 }
                 return signature;
             }
     }
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:50,代码来源:MetadataDecoder.cs

示例2: UncompressSlotMap

        private unsafe static ImmutableArray<LocalSlotDebugInfo> UncompressSlotMap(ImmutableArray<byte> compressedSlotMap)
        {
            if (compressedSlotMap.IsDefaultOrEmpty)
            {
                return default(ImmutableArray<LocalSlotDebugInfo>);
            }

            var mapBuilder = ArrayBuilder<LocalSlotDebugInfo>.GetInstance();
            int syntaxOffsetBaseline = -1;

            fixed (byte* compressedSlotMapPtr = &compressedSlotMap.ToArray()[0])
            {
                var blobReader = new BlobReader(compressedSlotMapPtr, compressedSlotMap.Length);
                while (blobReader.RemainingBytes > 0)
                {
                    byte b = blobReader.ReadByte();

                    if (b == SyntaxOffsetBaseline)
                    {
                        syntaxOffsetBaseline = -blobReader.ReadCompressedInteger();
                        continue;
                    }

                    if (b == 0)
                    {
                        // short-lived temp, no info
                        mapBuilder.Add(new LocalSlotDebugInfo(SynthesizedLocalKind.LoweringTemp, default(LocalDebugId)));
                        continue;
                    }

                    var kind = (SynthesizedLocalKind)((b & 0x3f) - 1);
                    bool hasOrdinal = (b & (1 << 7)) != 0;

                    int syntaxOffset;
                    if (!blobReader.TryReadCompressedInteger(out syntaxOffset))
                    {
                        // invalid data
                        return default(ImmutableArray<LocalSlotDebugInfo>);
                    }

                    syntaxOffset += syntaxOffsetBaseline;

                    int ordinal = 0;
                    if (hasOrdinal && !blobReader.TryReadCompressedInteger(out ordinal))
                    {
                        // invalid data
                        return default(ImmutableArray<LocalSlotDebugInfo>);
                    }

                    mapBuilder.Add(new LocalSlotDebugInfo(kind, new LocalDebugId(syntaxOffset, ordinal)));
                }
            }

            return mapBuilder.ToImmutableAndFree();
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:55,代码来源:EditAndContinueMethodDebugInformation.cs

示例3: DecodeGenericTypeArguments

 private ImmutableArray<TypeSignature> DecodeGenericTypeArguments(ref BlobReader signatureReader)
 {
     int typeArgCount;
     signatureReader.TryReadCompressedInteger(out typeArgCount);
     var builder = ImmutableArray.CreateBuilder<TypeSignature>(typeArgCount);
     for (int i = 0; i < typeArgCount; i++)
     {
         var typeArg = DecodeModifiersAndType(ref signatureReader);
         builder.Add(typeArg);
     }
     return builder.ToImmutable();
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:12,代码来源:MetadataDecoder.cs

示例4: WriteEditAndContinueLambdaMap

        private unsafe void WriteEditAndContinueLambdaMap(CustomDebugInfoRecord record)
        {
            Debug.Assert(record.Kind == CustomDebugInfoKind.EditAndContinueLambdaMap);

            _writer.WriteStartElement("encLambdaMap");
            try
            {
                if (record.Data.Length == 0)
                {
                    return;
                }

                int methodOrdinal = -1;
                int syntaxOffsetBaseline = -1;
                int closureCount;

                fixed (byte* blobPtr = &record.Data.ToArray()[0])
                {
                    var blobReader = new BlobReader(blobPtr, record.Data.Length);

                    if (!blobReader.TryReadCompressedInteger(out methodOrdinal))
                    {
                        _writer.WriteElementString("methodOrdinal", "?");
                        _writer.WriteEndElement();
                        return;
                    }

                    // [-1, inf)
                    methodOrdinal--;
                    _writer.WriteElementString("methodOrdinal", CultureInvariantToString(methodOrdinal));

                    if (!blobReader.TryReadCompressedInteger(out syntaxOffsetBaseline))
                    {
                        _writer.WriteElementString("baseline", "?");
                        _writer.WriteEndElement();
                        return;
                    }

                    syntaxOffsetBaseline = -syntaxOffsetBaseline;
                    if (!blobReader.TryReadCompressedInteger(out closureCount))
                    {
                        _writer.WriteElementString("closureCount", "?");
                        _writer.WriteEndElement();
                        return;
                    }

                    for (int i = 0; i < closureCount; i++)
                    {
                        _writer.WriteStartElement("closure");
                        try
                        {
                            int syntaxOffset;
                            if (!blobReader.TryReadCompressedInteger(out syntaxOffset))
                            {
                                _writer.WriteElementString("offset", "?");
                                break;
                            }

                            _writer.WriteAttributeString("offset", CultureInvariantToString(syntaxOffset + syntaxOffsetBaseline));
                        }
                        finally
                        {
                            _writer.WriteEndElement();
                        }
                    }

                    while (blobReader.RemainingBytes > 0)
                    {
                        _writer.WriteStartElement("lambda");
                        try
                        {
                            int syntaxOffset;
                            if (!blobReader.TryReadCompressedInteger(out syntaxOffset))
                            {
                                _writer.WriteElementString("offset", "?");
                                return;
                            }

                            _writer.WriteAttributeString("offset", CultureInvariantToString(syntaxOffset + syntaxOffsetBaseline));

                            int closureOrdinal;
                            if (!blobReader.TryReadCompressedInteger(out closureOrdinal))
                            {
                                _writer.WriteElementString("closure", "?");
                                return;
                            }

                            closureOrdinal -= 2;

                            if (closureOrdinal == -2)
                            {
                                _writer.WriteAttributeString("closure", "this");
                            }
                            else if (closureOrdinal != -1)
                            {
                                _writer.WriteAttributeString("closure",
                                    CultureInvariantToString(closureOrdinal) + (closureOrdinal >= closureCount ? " (invalid)" : ""));
                            }
                        }
                        finally
//.........这里部分代码省略.........
开发者ID:GloryChou,项目名称:roslyn,代码行数:101,代码来源:PdbToXml.cs

示例5: WriteEditAndContinueLocalSlotMap

        private unsafe void WriteEditAndContinueLocalSlotMap(CustomDebugInfoRecord record)
        {
            Debug.Assert(record.Kind == CustomDebugInfoKind.EditAndContinueLocalSlotMap);

            _writer.WriteStartElement("encLocalSlotMap");
            try
            {
                int syntaxOffsetBaseline = -1;

                fixed (byte* compressedSlotMapPtr = &record.Data.ToArray()[0])
                {
                    var blobReader = new BlobReader(compressedSlotMapPtr, record.Data.Length);

                    while (blobReader.RemainingBytes > 0)
                    {
                        byte b = blobReader.ReadByte();

                        if (b == 0xff)
                        {
                            if (!blobReader.TryReadCompressedInteger(out syntaxOffsetBaseline))
                            {
                                _writer.WriteElementString("baseline", "?");
                                return;
                            }

                            syntaxOffsetBaseline = -syntaxOffsetBaseline;
                            continue;
                        }

                        _writer.WriteStartElement("slot");

                        if (b == 0)
                        {
                            // short-lived temp, no info
                            _writer.WriteAttributeString("kind", "temp");
                        }
                        else
                        {
                            int synthesizedKind = (b & 0x3f) - 1;
                            bool hasOrdinal = (b & (1 << 7)) != 0;

                            int syntaxOffset;
                            bool badSyntaxOffset = !blobReader.TryReadCompressedInteger(out syntaxOffset);
                            syntaxOffset += syntaxOffsetBaseline;

                            int ordinal = 0;
                            bool badOrdinal = hasOrdinal && !blobReader.TryReadCompressedInteger(out ordinal);

                            _writer.WriteAttributeString("kind", CultureInvariantToString(synthesizedKind));
                            _writer.WriteAttributeString("offset", badSyntaxOffset ? "?" : CultureInvariantToString(syntaxOffset));

                            if (badOrdinal || hasOrdinal)
                            {
                                _writer.WriteAttributeString("ordinal", badOrdinal ? "?" : CultureInvariantToString(ordinal));
                            }
                        }

                        _writer.WriteEndElement();
                    }
                }
            }
            finally
            {
                _writer.WriteEndElement(); //encLocalSlotMap
            }
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:66,代码来源:PdbToXml.cs

示例6: UncompressLambdaMap

        private unsafe static void UncompressLambdaMap(
            ImmutableArray<byte> compressedLambdaMap,
            out int methodOrdinal,
            out ImmutableArray<ClosureDebugInfo> closures, 
            out ImmutableArray<LambdaDebugInfo> lambdas)
        {
            methodOrdinal = MethodDebugId.UndefinedOrdinal;
            closures = default(ImmutableArray<ClosureDebugInfo>);
            lambdas = default(ImmutableArray<LambdaDebugInfo>);

            if (compressedLambdaMap.IsDefaultOrEmpty)
            {
                return;
            }

            var closuresBuilder = ArrayBuilder<ClosureDebugInfo>.GetInstance();
            var lambdasBuilder = ArrayBuilder<LambdaDebugInfo>.GetInstance();

            int syntaxOffsetBaseline = -1;
            int closureCount;

            fixed (byte* blobPtr = &compressedLambdaMap.ToArray()[0])
            {
                var blobReader = new BlobReader(blobPtr, compressedLambdaMap.Length);

                if (!blobReader.TryReadCompressedInteger(out methodOrdinal))
                {
                    // invalid data
                    return;
                }

                // [-1, inf)
                methodOrdinal--;

                if (!blobReader.TryReadCompressedInteger(out syntaxOffsetBaseline))
                {
                    // invalid data
                    return;
                }

                syntaxOffsetBaseline = -syntaxOffsetBaseline;

                if (!blobReader.TryReadCompressedInteger(out closureCount))
                {
                    // invalid data
                    return;
                }

                for (int i = 0; i < closureCount; i++)
                {
                    int syntaxOffset;
                    if (!blobReader.TryReadCompressedInteger(out syntaxOffset))
                    {
                        // invalid data
                        return;
                    }

                    closuresBuilder.Add(new ClosureDebugInfo(syntaxOffset + syntaxOffsetBaseline));
                }

                while (blobReader.RemainingBytes > 0)
                {
                    int syntaxOffset;
                    if (!blobReader.TryReadCompressedInteger(out syntaxOffset))
                    {
                        // invalid data
                        return;
                    }

                    int closureOrdinal;
                    if (!blobReader.TryReadCompressedInteger(out closureOrdinal))
                    {
                        // invalid data
                        return;
                    }

                    closureOrdinal--;
                    if (closureOrdinal < -1 || closureOrdinal >= closureCount)
                    {
                        // invalid data
                        return;
                    }

                    lambdasBuilder.Add(new LambdaDebugInfo(syntaxOffset + syntaxOffsetBaseline, closureOrdinal));
                }
            }

            closures = closuresBuilder.ToImmutableAndFree();
            lambdas = lambdasBuilder.ToImmutableAndFree();
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:90,代码来源:EditAndContinueMethodDebugInformation.cs


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