本文整理汇总了C#中Microsoft.CodeAnalysis.TextLoader类的典型用法代码示例。如果您正苦于以下问题:C# TextLoader类的具体用法?C# TextLoader怎么用?C# TextLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextLoader类属于Microsoft.CodeAnalysis命名空间,在下文中一共展示了TextLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateRecoverableText
protected static ValueSource<TextAndVersion> CreateRecoverableText(TextLoader loader, DocumentId documentId, SolutionServices services)
{
return new RecoverableTextAndVersion(
new AsyncLazy<TextAndVersion>(c => LoadTextAsync(loader, documentId, services, c), cacheResult: false),
services.TemporaryStorage,
services.TextCache);
}
示例2: DocumentInfo
/// <summary>
/// Create a new instance of a <see cref="DocumentInfo"/>.
/// </summary>
private DocumentInfo(
DocumentId id,
string name,
IEnumerable<string> folders,
SourceCodeKind sourceCodeKind,
TextLoader loader,
string filePath,
bool isGenerated)
{
if (id == null)
{
throw new ArgumentNullException(nameof(id));
}
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
this.Id = id;
this.Name = name;
this.Folders = folders.ToImmutableReadOnlyListOrEmpty();
this.SourceCodeKind = sourceCodeKind;
this.TextLoader = loader;
this.FilePath = filePath;
this.IsGenerated = isGenerated;
}
示例3: StandardTextDocument
public StandardTextDocument(
DocumentProvider documentProvider,
IVisualStudioHostProject project,
DocumentKey documentKey,
IReadOnlyList<string> folderNames,
SourceCodeKind sourceCodeKind,
ITextUndoHistoryRegistry textUndoHistoryRegistry,
IVsFileChangeEx fileChangeService,
ITextBuffer openTextBuffer,
DocumentId id,
EventHandler updatedOnDiskHandler,
EventHandler<bool> openedHandler,
EventHandler<bool> closingHandler)
{
Contract.ThrowIfNull(documentProvider);
this.Project = project;
this.Id = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker);
this.Folders = folderNames;
_documentProvider = documentProvider;
this.Key = documentKey;
this.SourceCodeKind = sourceCodeKind;
_itemMoniker = documentKey.Moniker;
_textUndoHistoryRegistry = textUndoHistoryRegistry;
_fileChangeTracker = new FileChangeTracker(fileChangeService, this.FilePath);
_fileChangeTracker.UpdatedOnDisk += OnUpdatedOnDisk;
_openTextBuffer = openTextBuffer;
_snapshotTracker = new ReiteratedVersionSnapshotTracker(openTextBuffer);
// The project system does not tell us the CodePage specified in the proj file, so
// we use null to auto-detect.
_doNotAccessDirectlyLoader = new FileTextLoader(documentKey.Moniker, defaultEncoding: null);
// If we aren't already open in the editor, then we should create a file change notification
if (openTextBuffer == null)
{
_fileChangeTracker.StartFileChangeListeningAsync();
}
if (updatedOnDiskHandler != null)
{
UpdatedOnDisk += updatedOnDiskHandler;
}
if (openedHandler != null)
{
Opened += openedHandler;
}
if (closingHandler != null)
{
Closing += closingHandler;
}
}
示例4: Create
public static DocumentInfo Create(
DocumentId id,
string name,
IEnumerable<string> folders = null,
SourceCodeKind sourceCodeKind = SourceCodeKind.Regular,
TextLoader loader = null,
string filePath = null,
bool isGenerated = false)
{
return new DocumentInfo(id, name, folders, sourceCodeKind, loader, filePath, isGenerated);
}
示例5: StandardTextDocument
public StandardTextDocument(
DocumentProvider documentProvider,
IVisualStudioHostProject project,
DocumentKey documentKey,
uint itemId,
SourceCodeKind sourceCodeKind,
ITextBufferFactoryService textBufferFactoryService,
ITextUndoHistoryRegistry textUndoHistoryRegistry,
IVsFileChangeEx fileChangeService,
ITextBuffer openTextBuffer,
DocumentId id)
{
Contract.ThrowIfNull(documentProvider);
Contract.ThrowIfNull(textBufferFactoryService);
this.Project = project;
this.Id = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker);
this.Folders = project.GetFolderNames(itemId);
// TODO:
// this one doesn't work for asynchronous project load situation where shared projects is loaded after one uses shared file.
// we need to figure out what to do on those case. but this works for project k case.
// opened an issue to track this issue - https://github.com/dotnet/roslyn/issues/1859
this.SharedHierarchy = project.Hierarchy == null ? null : LinkedFileUtilities.GetSharedHierarchyForItem(project.Hierarchy, itemId);
_documentProvider = documentProvider;
this.Key = documentKey;
this.SourceCodeKind = sourceCodeKind;
_itemMoniker = documentKey.Moniker;
_textBufferFactoryService = textBufferFactoryService;
_textUndoHistoryRegistry = textUndoHistoryRegistry;
_fileChangeTracker = new FileChangeTracker(fileChangeService, this.FilePath);
_fileChangeTracker.UpdatedOnDisk += OnUpdatedOnDisk;
_openTextBuffer = openTextBuffer;
_snapshotTracker = new ReiteratedVersionSnapshotTracker(openTextBuffer);
// The project system does not tell us the CodePage specified in the proj file, so
// we use null to auto-detect.
_doNotAccessDirectlyLoader = new FileTextLoader(documentKey.Moniker, defaultEncoding: null);
// If we aren't already open in the editor, then we should create a file change notification
if (openTextBuffer == null)
{
_fileChangeTracker.StartFileChangeListeningAsync();
}
}
示例6: CreateStrongText
private static ValueSource<TextAndVersion> CreateStrongText(TextLoader loader, DocumentId documentId, SolutionServices services)
{
return new AsyncLazy<TextAndVersion>(c => LoadTextAsync(loader, documentId, services, c), cacheResult: true);
}
示例7: WithDocumentTextLoader
/// <summary>
/// Creates a new solution instance with the document specified updated to have the text
/// supplied by the text loader.
/// </summary>
public Solution WithDocumentTextLoader(DocumentId documentId, TextLoader loader, PreservationMode mode)
{
return WithDocumentTextLoader(documentId, loader, textOpt: null, mode: mode);
}
示例8: 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);
}
}
示例9: UpdateText
public TextDocumentState UpdateText(TextLoader loader, PreservationMode mode)
{
if (loader == null)
{
throw new ArgumentNullException(nameof(loader));
}
// don't blow up on non-text documents.
var newTextSource = (mode == PreservationMode.PreserveIdentity)
? CreateStrongText(loader, this.Id, this.solutionServices, reportInvalidDataException: false)
: CreateRecoverableText(loader, this.Id, this.solutionServices, reportInvalidDataException: false);
return new TextDocumentState(
this.solutionServices,
this.info,
textSource: newTextSource);
}
示例10: UpdateText
public TextDocumentState UpdateText(TextLoader loader, PreservationMode mode)
{
if (loader == null)
{
throw new ArgumentNullException("loader");
}
var newTextSource = (mode == PreservationMode.PreserveIdentity)
? CreateStrongText(loader, this.Id, this.solutionServices)
: CreateRecoverableText(loader, this.Id, this.solutionServices);
return new TextDocumentState(
this.solutionServices,
this.info,
textSource: newTextSource);
}
示例11: OnDocumentClosed
public void OnDocumentClosed(DocumentId documentId, ITextBuffer textBuffer, TextLoader loader, bool updateActiveContext) { }
示例12: OnAdditionalDocumentClosed
public void OnAdditionalDocumentClosed(DocumentId documentId, ITextBuffer textBuffer, TextLoader loader) { }
示例13: WithAdditionalDocumentTextLoader
/// <summary>
/// Creates a new solution instance with the additional document specified updated to have the text
/// supplied by the text loader.
/// </summary>
public Solution WithAdditionalDocumentTextLoader(DocumentId documentId, TextLoader loader, PreservationMode mode)
{
var newState = _state.WithAdditionalDocumentTextLoader(documentId, loader, mode);
if (newState == _state)
{
return this;
}
return new Solution(newState);
}
示例14: WithDocumentTextLoader
internal Solution WithDocumentTextLoader(DocumentId documentId, TextLoader loader, SourceText textOpt, PreservationMode mode)
{
var newState = _state.WithDocumentTextLoader(documentId, loader, textOpt, mode);
if (newState == _state)
{
return this;
}
return new Solution(newState);
}
示例15: DocumentInfo
/// <summary>
/// Create a new instance of a <see cref="DocumentInfo"/>.
/// </summary>
private DocumentInfo(DocumentAttributes attributes, TextLoader loader)
{
Attributes = attributes;
TextLoader = loader;
}