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


C# SourceHashAlgorithm类代码示例

本文整理汇总了C#中SourceHashAlgorithm的典型用法代码示例。如果您正苦于以下问题:C# SourceHashAlgorithm类的具体用法?C# SourceHashAlgorithm怎么用?C# SourceHashAlgorithm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: DebugSourceInfo

 public DebugSourceInfo(
     ImmutableArray<byte> checksum, 
     SourceHashAlgorithm checksumAlgorithm, 
     ImmutableArray<byte> embeddedTextBlob = default(ImmutableArray<byte>))
     : this(checksum, DebugSourceDocument.GetAlgorithmGuid(checksumAlgorithm), embeddedTextBlob)
 {
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:7,代码来源:DebugSourceInfo.cs

示例2: LargeTextWriter

 public LargeTextWriter(Encoding encoding, SourceHashAlgorithm checksumAlgorithm, int length)
 {
     _encoding = encoding;
     _checksumAlgorithm = checksumAlgorithm;
     _chunks = ArrayBuilder<char[]>.GetInstance(1 + length / LargeText.ChunkSize);
     _bufferSize = Math.Min(LargeText.ChunkSize, length);
 }
开发者ID:jeffanders,项目名称:roslyn,代码行数:7,代码来源:LargeTextWriter.cs

示例3: Decode

        internal static SourceText Decode(Stream stream, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
        {
            stream.Seek(0, SeekOrigin.Begin);

            long longLength = stream.Length;
            if (longLength == 0)
            {
                return SourceText.From(string.Empty, encoding, checksumAlgorithm);
            }

            var maxCharRemainingGuess = encoding.GetMaxCharCountOrThrowIfHuge(stream);
            Debug.Assert(longLength > 0 && longLength <= int.MaxValue); // GetMaxCharCountOrThrowIfHuge should have thrown.
            int length = (int)longLength;

            using (var reader = new StreamReader(stream, encoding, detectEncodingFromByteOrderMarks: true, bufferSize: Math.Min(length, 4096), leaveOpen: true))
            {
                var chunks = ReadChunksFromTextReader(reader, maxCharRemainingGuess, throwIfBinaryDetected);

                // We must compute the checksum and embedded text blob now while we still have the original bytes in hand.
                // We cannot re-encode to obtain checksum and blob as the encoding is not guaranteed to round-trip.
                var checksum = CalculateChecksum(stream, checksumAlgorithm);
                var embeddedTextBlob = canBeEmbedded ? EmbeddedText.CreateBlob(stream) : default(ImmutableArray<byte>);
                return new LargeText(chunks, reader.CurrentEncoding, checksum, checksumAlgorithm, embeddedTextBlob);
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:25,代码来源:LargeText.cs

示例4: Create

        // internal for testing
        internal static SourceText Create(Stream stream, Func<Encoding> getEncoding,
            Encoding defaultEncoding = null,
            SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
        {
            Debug.Assert(stream != null);
            Debug.Assert(stream.CanRead && stream.CanSeek);

            bool detectEncoding = defaultEncoding == null;
            if (detectEncoding)
            {
                try
                {
                    return Decode(stream, s_utf8Encoding, checksumAlgorithm, throwIfBinaryDetected: false);
                }
                catch (DecoderFallbackException)
                {
                    // Fall back to Encoding.ASCII
                }
            }

            try
            {
                return Decode(stream, defaultEncoding ?? getEncoding(), checksumAlgorithm, throwIfBinaryDetected: detectEncoding);
            }
            catch (DecoderFallbackException e)
            {
                throw new InvalidDataException(e.Message);
            }

        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:31,代码来源:EncodedStringText.cs

示例5: ValidateChecksumAlgorithm

 internal static void ValidateChecksumAlgorithm(SourceHashAlgorithm checksumAlgorithm)
 {
     if (!Cci.DebugSourceDocument.IsSupportedAlgorithm(checksumAlgorithm))
     {
         throw new ArgumentException(CodeAnalysisResources.UnsupportedHashAlgorithm, nameof(checksumAlgorithm));
     }
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:7,代码来源:SourceText.cs

示例6: Decode

        internal static SourceText Decode(Stream stream, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
        {
            stream.Seek(0, SeekOrigin.Begin);

            long longLength = stream.Length;
            if (longLength == 0)
            {
                return SourceText.From(string.Empty, encoding, checksumAlgorithm);
            }

            var maxCharRemainingGuess = encoding.GetMaxCharCountOrThrowIfHuge(stream);
            Debug.Assert(longLength > 0 && longLength <= int.MaxValue); // GetMaxCharCountOrThrowIfHuge should have thrown.
            int length = (int)longLength;

            using (var reader = new StreamReader(stream, encoding, detectEncodingFromByteOrderMarks: true, bufferSize: Math.Min(length, 4096), leaveOpen: true))
            {
                ArrayBuilder<char[]> chunks = ArrayBuilder<char[]>.GetInstance(1 + maxCharRemainingGuess / ChunkSize);
                while (!reader.EndOfStream)
                {
                    var nextChunkSize = ChunkSize;
                    if (maxCharRemainingGuess < ChunkSize)
                    {
                        // maxCharRemainingGuess typically overestimates a little
                        // so we will first fill a slightly smaller (maxCharRemainingGuess - 64) chunk
                        // and then use 64 char tail, which is likley to be resized.
                        nextChunkSize = Math.Max(maxCharRemainingGuess - 64, 64);
                    }

                    char[] chunk = new char[nextChunkSize];

                    int charsRead = reader.ReadBlock(chunk, 0, chunk.Length);
                    if (charsRead == 0)
                    {
                        break;
                    }

                    maxCharRemainingGuess -= charsRead;

                    if (charsRead < chunk.Length)
                    {
                        Array.Resize(ref chunk, charsRead);
                    }

                    // Check for binary files
                    if (throwIfBinaryDetected && IsBinary(chunk))
                    {
                        throw new InvalidDataException();
                    }

                    chunks.Add(chunk);
                }

                // We must compute the checksum and embedded text blob now while we still have the original bytes in hand.
                // We cannot re-encode to obtain checksum and blob as the encoding is not guaranteed to round-trip.
                var checksum = CalculateChecksum(stream, checksumAlgorithm);
                var embeddedTextBlob = canBeEmbedded ? EmbeddedText.CreateBlob(stream) : default(ImmutableArray<byte>);
                return new LargeText(chunks.ToImmutableAndFree(), reader.CurrentEncoding, checksum, checksumAlgorithm, embeddedTextBlob);
            }
        }
开发者ID:tvsonar,项目名称:roslyn,代码行数:59,代码来源:LargeText.cs

示例7: StringText

        internal StringText(string source, Encoding encodingOpt, ImmutableArray<byte> checksum = default(ImmutableArray<byte>), SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
            : base(checksum, checksumAlgorithm)
        {
            Debug.Assert(source != null);

            _source = source;
            _encodingOpt = encodingOpt;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:8,代码来源:StringText.cs

示例8: StringBuilderText

        public StringBuilderText(StringBuilder builder, Encoding encodingOpt, SourceHashAlgorithm checksumAlgorithm)
             : base(checksumAlgorithm: checksumAlgorithm)
        {
            Debug.Assert(builder != null);

            _builder = builder;
            _encodingOpt = encodingOpt;
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:8,代码来源:StringBuilderText.cs

示例9: From

        /// <summary>
        /// Constructs a <see cref="SourceText"/> from text in a string.
        /// </summary>
        /// <param name="text">Text.</param>
        /// <param name="encoding">
        /// Encoding of the file that the <paramref name="text"/> was read from or is going to be saved to.
        /// <c>null</c> if the encoding is unspecified.
        /// If the encoding is not specified the resulting <see cref="SourceText"/> isn't debuggable.
        /// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
        /// </param>
        /// <param name="checksumAlgorithm">
        /// Hash algorithm to use to calculate checksum of the text that's saved to PDB.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="text"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="checksumAlgorithm"/> is not supported.</exception>
        public static SourceText From(string text, Encoding encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            return new StringText(text, encoding, checksumAlgorithm: checksumAlgorithm);
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:24,代码来源:SourceText.cs

示例10: EmbeddedText

        private EmbeddedText(string filePath, ImmutableArray<byte> checksum, SourceHashAlgorithm checksumAlgorithm, ImmutableArray<byte> blob)
        {
            Debug.Assert(filePath?.Length > 0);
            Debug.Assert(Cci.DebugSourceDocument.IsSupportedAlgorithm(checksumAlgorithm));
            Debug.Assert(!blob.IsDefault && blob.Length >= sizeof(int));

            FilePath = filePath;
            Checksum = checksum;
            ChecksumAlgorithm = checksumAlgorithm;
            Blob = blob;
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:11,代码来源:EmbeddedText.cs

示例11: Decode

        internal static SourceText Decode(Stream stream, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected)
        {
            stream.Seek(0, SeekOrigin.Begin);

            int length = (int)stream.Length;
            if (length == 0)
            {
                return SourceText.From(string.Empty, encoding, checksumAlgorithm);
            }

            var maxCharRemainingGuess = encoding.GetMaxCharCount(length);

            using (var reader = new StreamReader(stream, encoding, detectEncodingFromByteOrderMarks: true, bufferSize: Math.Min(length, 4096), leaveOpen: true))
            {
                ArrayBuilder<char[]> chunks = ArrayBuilder<char[]>.GetInstance(1 + maxCharRemainingGuess / ChunkSize);
                while (!reader.EndOfStream)
                {
                    var nextChunkSize = ChunkSize;
                    if (maxCharRemainingGuess < ChunkSize)
                    {
                        // maxCharRemainingGuess typically overestimates a little
                        // so we will first fill a slightly smaller (maxCharRemainingGuess - 64) chunk
                        // and then use 64 char tail, which is likley to be resized.
                        nextChunkSize = Math.Max(maxCharRemainingGuess - 64, 64);
                    }

                    char[] chunk = new char[nextChunkSize];

                    int charsRead = reader.ReadBlock(chunk, 0, chunk.Length);
                    if (charsRead == 0)
                    {
                        break;
                    }

                    maxCharRemainingGuess -= charsRead;

                    if (charsRead < chunk.Length)
                    {
                        Array.Resize(ref chunk, charsRead);
                    }

                    // Check for binary files
                    if (throwIfBinaryDetected && IsBinary(chunk))
                    {
                        throw new InvalidDataException();
                    }

                    chunks.Add(chunk);
                }

                var checksum = CalculateChecksum(stream, checksumAlgorithm);
                return new LargeText(chunks.ToImmutableAndFree(), reader.CurrentEncoding, checksum, checksumAlgorithm);
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:54,代码来源:LargeText.cs

示例12: Create

 /// <summary>
 /// Initializes an instance of <see cref="SourceText"/> from the provided stream. This version differs
 /// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
 /// 1. It attempts to minimize allocations by trying to read the stream into a byte array.
 /// 2. If <paramref name="defaultEncoding"/> is null, it will first try UTF8 and, if that fails, it will
 ///    try CodePage 1252. If CodePage 1252 is not available on the system, then it will try Latin1.
 /// </summary>
 /// <param name="stream">The stream containing encoded text.</param>
 /// <param name="defaultEncoding">
 /// Specifies an encoding to be used if the actual encoding can't be determined from the stream content (the stream doesn't start with Byte Order Mark).
 /// If not specified auto-detect heuristics are used to determine the encoding. If these heuristics fail the decoding is assumed to be Encoding.Default.
 /// Note that if the stream starts with Byte Order Mark the value of <paramref name="defaultEncoding"/> is ignored.
 /// </param>
 /// <param name="canBeEmbedded">Indicates if the file can be embedded in the PDB.</param>
 /// <param name="checksumAlgorithm">Hash algorithm used to calculate document checksum.</param>
 /// <exception cref="InvalidDataException">
 /// The stream content can't be decoded using the specified <paramref name="defaultEncoding"/>, or
 /// <paramref name="defaultEncoding"/> is null and the stream appears to be a binary file.
 /// </exception>
 /// <exception cref="IOException">An IO error occurred while reading from the stream.</exception>
 internal static SourceText Create(Stream stream,
     Encoding defaultEncoding = null,
     SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1,
     bool canBeEmbedded = false)
 {
     return Create(stream,
         s_fallbackEncoding,
         defaultEncoding: defaultEncoding,
         checksumAlgorithm: checksumAlgorithm,
         canBeEmbedded: canBeEmbedded);
 }
开发者ID:tvsonar,项目名称:roslyn,代码行数:31,代码来源:EncodedStringText.cs

示例13: Create

 public static SourceTextWriter Create(Encoding encoding, SourceHashAlgorithm checksumAlgorithm, int length)
 {
     if (length < SourceText.LargeObjectHeapLimitInChars)
     {
         return new StringTextWriter(encoding, checksumAlgorithm, length);
     }
     else
     {
         return new LargeTextWriter(encoding, checksumAlgorithm, length);
     }
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:11,代码来源:SourceTextWriter.cs

示例14: CreateMemoryStreamBasedEncodedText

        private static SourceText CreateMemoryStreamBasedEncodedText(byte[] bytes, Encoding readEncodingOpt, SourceHashAlgorithm algorithm = SourceHashAlgorithm.Sha1)
        {
            // For testing purposes, create a bigger buffer so that we verify 
            // that the implementation only uses the part that's covered by the stream and not the entire array.
            byte[] buffer = new byte[bytes.Length + 10];
            bytes.CopyTo(buffer, 0);

            using (var stream = new MemoryStream(buffer, 0, bytes.Length, writable: true, publiclyVisible: true))
            {
                return EncodedStringText.Create(stream, readEncodingOpt, algorithm);
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:12,代码来源:StringTextDecodingTests.cs

示例15: EncodedStringText

        private const int LargeObjectHeapLimit = 80 * 1024; // 80KB

        private EncodedStringText(string source, Encoding encoding, ImmutableArray<byte> checksum, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinary)
            : base(checksum: checksum, checksumAlgorithm: checksumAlgorithm)
        {
            if (throwIfBinary && IsBinary(source))
            {
                throw new InvalidDataException();
            }

            Debug.Assert(source != null);
            Debug.Assert(encoding != null);
            _source = source;
            _encoding = encoding;
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:15,代码来源:EncodedStringText.cs


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