本文整理汇总了C#中Microsoft.CodeAnalysis.Project.RemoveDocument方法的典型用法代码示例。如果您正苦于以下问题:C# Project.RemoveDocument方法的具体用法?C# Project.RemoveDocument怎么用?C# Project.RemoveDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.Project
的用法示例。
在下文中一共展示了Project.RemoveDocument方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveNonExistingDocuments
private static Solution RemoveNonExistingDocuments(Project project)
{
foreach (var documentId in project.DocumentIds.ToArray())
{
var document = project.GetDocument(documentId);
if (!File.Exists(document.FilePath))
{
Log.Message("Document doesn't exist on disk: " + document.FilePath);
project = project.RemoveDocument(documentId);
}
}
return project.Solution;
}
示例2: DisambiguateSameNameLinkedFiles
/// <summary>
/// If there are two linked files both outside the project cone, and they have same names,
/// they will logically appear as the same file in the project root. To disambiguate, we
/// remove both files from the project's root and re-add them each into a folder chain that
/// is formed from the full path of each document.
/// </summary>
private static Solution DisambiguateSameNameLinkedFiles(Project project)
{
var nameMap = project.Documents.Where(d => !d.Folders.Any()).ToLookup(d => d.Name);
foreach (var conflictedItemGroup in nameMap.Where(g => g.Count() > 1))
{
foreach (var conflictedDocument in conflictedItemGroup)
{
project = project.RemoveDocument(conflictedDocument.Id);
string filePath = conflictedDocument.FilePath;
DocumentId newId = DocumentId.CreateNewId(project.Id, filePath);
var folders = filePath.Split('\\').Select(p => p.TrimEnd(':'));
project = project.Solution.AddDocument(
newId,
conflictedDocument.Name,
conflictedDocument.GetTextAsync().Result,
folders,
filePath).GetProject(project.Id);
}
}
return project.Solution;
}
示例3: AddPathToProject
private static void AddPathToProject(ref Solution solution, ref Project project, string fileName, string contents)
{
var document = GetExistingDocument(project, fileName);
if (document != null)
{
project = project.RemoveDocument(document.Id);
solution = project.Solution;
}
Console.WriteLine($"\t - Adding {fileName} to project");
document = project.AddDocument(fileName,
contents,
null,
Path.Combine(Path.GetDirectoryName(project.FilePath), fileName));
project = document.Project;
solution = project.Solution;
}
示例4: ApplyChanges
private void ApplyChanges()
{
foreach (var doc in Tasks)
{
_project = _generatorWorkspace.Solution?.Projects.FirstOrDefault(x => x.Name == doc.Item4);
var oldDocument = _project?.Documents.FirstOrDefault(x => x.Name == doc.Item1);
if (oldDocument != null)
{
if (oldDocument.GetTextAsync().Result.ToString() != doc.Item2.ToString())
{
bool isEqual = oldDocument.Folders.SequenceEqual(doc.Item3);
if (isEqual)
{
_project = _project.RemoveDocument(oldDocument.Id);
}
var newDocument = _project?.AddDocument(doc.Item1, doc.Item2, doc.Item3);
_project = newDocument?.Project;
_generatorWorkspace.Solution = _project?.Solution;
}
}
else
{
var newDocument = _project?.AddDocument(doc.Item1, doc.Item2, doc.Item3);
_project = newDocument?.Project;
_generatorWorkspace.Solution = _project?.Solution;
}
}
}
示例5: ApplyChanges
private void ApplyChanges()
{
var dirCompletedEventArgs = new DirectoryInfo(_project.FilePath.Remove(_project.FilePath.LastIndexOf("\\", StringComparison.Ordinal)) + "\\ServiceReferences\\CompletedEventArgs");
foreach (FileInfo file in dirCompletedEventArgs.GetFiles())
{
var redundantDocument = _project?.Documents.FirstOrDefault(x => x.Name == file.Name);
if (redundantDocument != null && _competedArgsMethods.All(x => (x.Service + "_" + x.Name + "CompletedEventArgs") != file.Name.Remove(file.Name.IndexOf(".", StringComparison.Ordinal))))
_project = _project?.RemoveDocument(redundantDocument.Id);
}
foreach (var doc in tasks)
{
_project = _generatorWorkspace.Solution?.Projects.FirstOrDefault(x => x.Name == doc.Item4);
var oldDocument = _project?.Documents.FirstOrDefault(x => x.Name == doc.Item1);
if (oldDocument != null)
{
if (oldDocument.GetTextAsync().Result.ToString() != doc.Item2.ToString())
{
bool isEqual = oldDocument.Folders.SequenceEqual(doc.Item3);
if (isEqual)
{
_project = _project.RemoveDocument(oldDocument.Id);
}
var newDocument = _project?.AddDocument(doc.Item1, doc.Item2, doc.Item3);
_project = newDocument?.Project;
_generatorWorkspace.Solution = _project?.Solution;
}
}
else
{
var newDocument = _project?.AddDocument(doc.Item1, doc.Item2, doc.Item3);
_project = newDocument?.Project;
_generatorWorkspace.Solution = _project?.Solution;
}
}
_generatorWorkspace.Solution = _project.Solution;
_generatorWorkspace.ApplyChanges();
}