本文整理汇总了C#中Microsoft.CodeAnalysis.TextLoader.LoadTextAndVersionAsync方法的典型用法代码示例。如果您正苦于以下问题:C# TextLoader.LoadTextAndVersionAsync方法的具体用法?C# TextLoader.LoadTextAndVersionAsync怎么用?C# TextLoader.LoadTextAndVersionAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.TextLoader
的用法示例。
在下文中一共展示了TextLoader.LoadTextAndVersionAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadTextAsync
protected static async Task<TextAndVersion> LoadTextAsync(TextLoader loader, DocumentId documentId, SolutionServices services, bool reportInvalidDataException, CancellationToken cancellationToken)
{
int retries = 0;
while (true)
{
try
{
using (ExceptionHelpers.SuppressFailFast())
{
var result = await loader.LoadTextAndVersionAsync(services.Workspace, documentId, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
return result;
}
}
catch (OperationCanceledException)
{
// if load text is failed due to a cancellation, make sure we propagate it out to the caller
throw;
}
catch (IOException e)
{
if (++retries > MaxRetries)
{
services.Workspace.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.Failure, e.Message, documentId));
return TextAndVersion.Create(SourceText.From(string.Empty, Encoding.UTF8), VersionStamp.Default, documentId.GetDebuggerDisplay());
}
// fall out to try again
}
catch (InvalidDataException e)
{
// TODO: Adjust this behavior in the future if we add support for non-text additional files
if (reportInvalidDataException)
{
services.Workspace.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.Failure, e.Message, documentId));
}
return TextAndVersion.Create(SourceText.From(string.Empty, Encoding.UTF8), VersionStamp.Default, documentId.GetDebuggerDisplay());
}
// try again after a delay
await Task.Delay(RetryDelay).ConfigureAwait(false);
}
}
示例2: LoadTextAsync
private static async Task<TextAndVersion> LoadTextAsync(TextLoader loader, DocumentId documentId, SolutionServices services, CancellationToken cancellationToken)
{
try
{
using (ExceptionHelpers.SuppressFailFast())
{
var result = await loader.LoadTextAndVersionAsync(services.Workspace, documentId, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
return result;
}
}
catch (OperationCanceledException)
{
// if load text is failed due to a cancellation, make sure we propagate it out to the caller
throw;
}
catch (IOException e)
{
services.Workspace.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.Failure, e.Message, documentId));
return TextAndVersion.Create(SourceText.From(string.Empty, Encoding.UTF8), VersionStamp.Default, documentId.GetDebuggerDisplay());
}
}