• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# SourceHashAlgorithm类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: SourceText

        protected SourceText(ImmutableArray<byte> checksum = default(ImmutableArray<byte>), SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1, SourceTextContainer container = null)
        {
            ValidateChecksumAlgorithm(checksumAlgorithm);

            if (!checksum.IsDefault && checksum.Length != CryptographicHashProvider.GetHashSize(checksumAlgorithm))
            {
                throw new ArgumentException(CodeAnalysisResources.InvalidHash, nameof(checksum));
            }

            _checksumAlgorithm = checksumAlgorithm;
            _lazyChecksum = checksum;
            _lazyContainer = container;
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:13,代码来源:SourceText.cs


示例17: GetHashSize

        internal static int GetHashSize(SourceHashAlgorithm algorithmId)
        {
            switch (algorithmId)
            {
                case SourceHashAlgorithm.Sha1:
                    return 160 / 8;

                case SourceHashAlgorithm.Sha256:
                    return 256 / 8;

                default:
                    throw ExceptionUtilities.UnexpectedValue(algorithmId);
            }
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:14,代码来源:CryptographicHashProvider.cs


示例18: TryGetAlgorithm

        internal static HashAlgorithm TryGetAlgorithm(SourceHashAlgorithm algorithmId)
        {
            switch (algorithmId)
            {
                case SourceHashAlgorithm.Sha1:
                    return new SHA1CryptoServiceProvider();

                case SourceHashAlgorithm.Sha256:
                    return new SHA256CryptoServiceProvider();

                default:
                    return null;
            }
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:14,代码来源:CryptographicHashProvider.cs


示例19: TryGetAlgorithm

        internal static HashAlgorithm TryGetAlgorithm(SourceHashAlgorithm algorithmId)
        {
            switch (algorithmId)
            {
                case SourceHashAlgorithm.Sha1:
                    return SHA1.Create();

                case SourceHashAlgorithm.Sha256:
                    return SHA256.Create();

                default:
                    return null;
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:14,代码来源:CryptographicHashProvider.cs


示例20: LargeText

        internal LargeText(ImmutableArray<char[]> chunks, Encoding encoding, ImmutableArray<byte> checksum, SourceHashAlgorithm checksumAlgorithm, ImmutableArray<byte> embeddedTextBlob)
            : base(checksum, checksumAlgorithm, embeddedTextBlob)
        {
            _chunks = chunks;
            _encoding = encoding;
            _chunkStartOffsets = new int[chunks.Length];
            int offset = 0;
            for (int i = 0; i < chunks.Length; i++)
            {
                _chunkStartOffsets[i] = offset;
                offset += chunks[i].Length;
            }

            _length = offset;
        }
开发者ID:tvsonar,项目名称:roslyn,代码行数:15,代码来源:LargeText.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SourceLevels类代码示例发布时间:2022-05-24
下一篇:
C# SourceGrid类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap