本文整理汇总了C#中Microsoft.CodeAnalysis.Solution.GetChanges方法的典型用法代码示例。如果您正苦于以下问题:C# Solution.GetChanges方法的具体用法?C# Solution.GetChanges怎么用?C# Solution.GetChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.Solution
的用法示例。
在下文中一共展示了Solution.GetChanges方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CleanSolutionAsync
private async Task<Solution> CleanSolutionAsync(Solution newSolution, Solution oldSolution, CancellationToken cancellationToken)
{
var solution = newSolution;
foreach (var projectChange in newSolution.GetChanges(oldSolution).GetProjectChanges())
{
foreach (var documentId in projectChange.GetChangedDocuments())
{
solution = await CleanSolutionDocument(solution, documentId, cancellationToken);
}
}
return solution;
}
示例2: GetChangedDocuments
static IEnumerable<DocumentId> GetChangedDocuments (Solution newSolution, Solution oldSolution)
{
if (newSolution != null) {
var solutionChanges = newSolution.GetChanges (oldSolution);
foreach (var projectChanges in solutionChanges.GetProjectChanges ()) {
foreach (var documentId in projectChanges.GetChangedDocuments ()) {
yield return documentId;
}
}
}
}
示例3: GetFileChangesAsync
public static async Task<IEnumerable<ModifiedFileResponse>> GetFileChangesAsync(Solution newSolution, Solution oldSolution, string newFileDirectory, bool wantTextChanges)
{
var changes = new Dictionary<string, ModifiedFileResponse>();
var solutionChanges = newSolution.GetChanges(oldSolution);
foreach (var projectChange in solutionChanges.GetProjectChanges())
{
foreach (var changedDocumentId in projectChange.GetAddedDocuments())
{
var document = newSolution.GetDocument(changedDocumentId);
var source = await document.GetTextAsync();
var modifiedFileResponse = new ModifiedFileResponse(document.Name);
var change = new LinePositionSpanTextChange();
change.NewText = source.ToString();
var newPath = Path.Combine(newFileDirectory, document.Name);
modifiedFileResponse.FileName = newPath;
modifiedFileResponse.Changes = new[] { change };
changes[newPath] = modifiedFileResponse;
// This is a little weird. The added document doesn't have a filepath
// and we need one so that future operations on this document work
var id = DocumentId.CreateNewId(document.Project.Id);
var version = VersionStamp.Create();
var documentInfo = DocumentInfo.Create(id, document.Name, filePath: newPath, loader: TextLoader.From(TextAndVersion.Create(source, version)));
var workspace = newSolution.Workspace as OmnisharpWorkspace;
workspace.RemoveDocument(changedDocumentId);
workspace.AddDocument(documentInfo);
}
foreach (var changedDocumentId in projectChange.GetChangedDocuments())
{
var changedDocument = newSolution.GetDocument(changedDocumentId);
ModifiedFileResponse modifiedFileResponse;
var filePath = changedDocument.FilePath;
if (!changes.TryGetValue(filePath, out modifiedFileResponse))
{
modifiedFileResponse = new ModifiedFileResponse(filePath);
changes[filePath] = modifiedFileResponse;
}
if (!wantTextChanges)
{
var changedText = await changedDocument.GetTextAsync();
modifiedFileResponse.Buffer = changedText.ToString();
}
else
{
var originalDocument = oldSolution.GetDocument(changedDocumentId);
IEnumerable<TextChange> textChanges;
textChanges = await changedDocument.GetTextChangesAsync(originalDocument);
var linePositionSpanTextChanges = await LinePositionSpanTextChange.Convert(originalDocument, textChanges);
modifiedFileResponse.Changes = modifiedFileResponse.Changes != null
? modifiedFileResponse.Changes.Union(linePositionSpanTextChanges)
: linePositionSpanTextChanges;
}
}
}
return changes.Values;
}