本文整理汇总了C#中Microsoft.CodeAnalysis.Text.SourceText.Write方法的典型用法代码示例。如果您正苦于以下问题:C# SourceText.Write方法的具体用法?C# SourceText.Write怎么用?C# SourceText.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.Text.SourceText
的用法示例。
在下文中一共展示了SourceText.Write方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyDocumentTextChanged
protected override void ApplyDocumentTextChanged(DocumentId documentId, SourceText text)
{
var document = this.CurrentSolution.GetDocument(documentId);
if (document != null)
{
try
{
using (var writer = new StreamWriter(document.FilePath, append: false, encoding: text.Encoding ?? s_utf8WithoutBom))
{
text.Write(writer);
}
}
catch (IOException e)
{
this.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.Failure, e.Message, documentId));
}
catch (UnauthorizedAccessException e)
{
this.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.Failure, e.Message, documentId));
}
this.OnDocumentTextChanged(documentId, text, PreservationMode.PreserveValue);
}
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:24,代码来源:ResponseFileWorkspace.cs
示例2: SaveDocumentText
private void SaveDocumentText(DocumentId id, string fullPath, SourceText newText, Encoding encoding)
{
try
{
using (ExceptionHelpers.SuppressFailFast())
{
var dir = Path.GetDirectoryName(fullPath);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
Debug.Assert(encoding != null);
using (var writer = new StreamWriter(fullPath, append: false, encoding: encoding))
{
newText.Write(writer);
}
}
}
catch (IOException exception)
{
this.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.Failure, exception.Message, id));
}
}
示例3: WriteText
public void WriteText(SourceText text, CancellationToken cancellationToken)
{
if (_memoryMappedInfo != null)
{
throw new InvalidOperationException();
}
using (Logger.LogBlock(FunctionId.TemporaryStorageServiceFactory_WriteText, cancellationToken))
{
_encoding = text.Encoding;
// the method we use to get text out of SourceText uses Unicode (2bytes per char).
var size = Encoding.Unicode.GetMaxByteCount(text.Length);
_memoryMappedInfo = _service._memoryMappedFileManager.CreateViewInfo(size);
// Write the source text out as Unicode. We expect that to be cheap.
using (var stream = _memoryMappedInfo.CreateWritableStream())
{
using (var writer = new StreamWriter(stream, Encoding.Unicode))
{
text.Write(writer, cancellationToken);
}
}
}
}
示例4: CreateBlob
private static ImmutableArray<byte> CreateBlob(SourceText text)
{
Debug.Assert(text != null);
Debug.Assert(text.CanBeEmbedded);
Debug.Assert(text.Encoding != null);
Debug.Assert(text.PrecomputedEmbeddedTextBlob.IsDefault);
int maxByteCount;
try
{
maxByteCount = text.Encoding.GetMaxByteCount(text.Length);
}
catch (ArgumentOutOfRangeException)
{
// Encoding does not provide a way to predict that max byte count would not
// fit in Int32 and we must therefore catch ArgumentOutOfRange to handle that
// case.
maxByteCount = int.MaxValue;
}
using (var builder = BlobBuildingStream.GetInstance())
{
if (maxByteCount < CompressionThreshold)
{
builder.WriteInt32(0);
using (var writer = new StreamWriter(builder, text.Encoding, bufferSize: Math.Max(1, text.Length), leaveOpen: true))
{
text.Write(writer);
}
}
else
{
Blob reserved = builder.ReserveBytes(4);
using (var deflater = new CountingDeflateStream(builder, CompressionLevel.Optimal, leaveOpen: true))
{
using (var writer = new StreamWriter(deflater, text.Encoding, bufferSize: 1024, leaveOpen: true))
{
text.Write(writer);
}
new BlobWriter(reserved).WriteInt32(deflater.BytesWritten);
}
}
return builder.ToImmutableArray();
}
}
示例5: SaveDocumentText
private void SaveDocumentText(DocumentId id, string fullPath, SourceText newText)
{
try
{
var dir = Path.GetDirectoryName(fullPath);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
using (var writer = new StreamWriter(fullPath))
{
newText.Write(writer);
}
}
catch (System.IO.IOException exception)
{
this.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.FileAccessFailure, exception.Message, id));
}
}
示例6: 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);
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))
{
text.Write(writer, cancellationToken);
}
}
}
}
示例7: WriteText
public void WriteText(SourceText text, CancellationToken cancellationToken = default(CancellationToken))
{
lock (writeTextLocker) {
if (fileName == null)
this.fileName = Path.GetTempFileName ();
string tmpPath = Path.Combine (Path.GetDirectoryName (fileName), ".#" + Path.GetFileName (fileName));
encoding = text.Encoding ?? Encoding.Default;
using (var writer = new StreamWriter (tmpPath, false, encoding))
text.Write (writer, cancellationToken);
sourceText = new WeakReference<SourceText>(text);
FileService.SystemRename (tmpPath, fileName);
}
}