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


C# SourceText.CopyTo方法代码示例

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


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

示例1: ContentEqualsImpl

        /// <summary>
        /// Implements equality comparison of the content of two different instances of <see cref="SourceText"/>.
        /// </summary>
        protected virtual bool ContentEqualsImpl(SourceText other)
        {
            if (other == null)
            {
                return false;
            }

            if (ReferenceEquals(this, other))
            {
                return true;
            }

            if (this.Length != other.Length)
            {
                return false;
            }

            var buffer1 = s_charArrayPool.Allocate();
            var buffer2 = s_charArrayPool.Allocate();
            try
            {
                int position = 0;
                while (position < this.Length)
                {
                    int n = Math.Min(this.Length - position, buffer1.Length);
                    this.CopyTo(position, buffer1, 0, n);
                    other.CopyTo(position, buffer2, 0, n);

                    for (int i = 0; i < n; i++)
                    {
                        if (buffer1[i] != buffer2[i])
                        {
                            return false;
                        }
                    }

                    position += n;
                }

                return true;
            }
            finally
            {
                s_charArrayPool.Free(buffer2);
                s_charArrayPool.Free(buffer1);
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:50,代码来源:SourceText.cs

示例2: WriteText

                public void WriteText(SourceText text, CancellationToken cancellationToken)
                {
                    if (memoryMappedInfo != null)
                    {
                        throw new InvalidOperationException();
                    }

                    using (Logger.LogBlock(FeatureId.TemporaryStorage, FunctionId.Host_TemporaryStorageServiceFactory_WriteText, cancellationToken))
                    {
                        var size = Encoding.Unicode.GetMaxByteCount(text.Length);
                        memoryMappedInfo = service.memoryMappedFileManager.CreateViewInfo(size);

                        var buffer = SharedPools.CharArray.Allocate();
                        using (var stream = memoryMappedInfo.CreateWritableStream())
                        {
                            // PERF: Don't call text.Write(writer) directly since it can cause multiple large string
                            // allocations from String.Substring.  Instead use one of our pooled char[] buffers.
                            using (var writer = new StreamWriter(stream, Encoding.Unicode))
                            {
                                for (int index = 0; index < text.Length; index += buffer.Length)
                                {
                                    cancellationToken.ThrowIfCancellationRequested();
                                    var count = Math.Min(buffer.Length, text.Length - index);
                                    text.CopyTo(index, buffer, 0, count);
                                    writer.Write(buffer, 0, count);
                                }
                            }
                        }

                        SharedPools.CharArray.Free(buffer);
                    }
                }
开发者ID:nagyist,项目名称:roslyn,代码行数:32,代码来源:TemporaryStorageServiceFactory.cs


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