refactor
This commit is contained in:
@@ -15,40 +15,35 @@ public static class IntermediateMapper
|
||||
|
||||
var rootFolders = vsSolution.SolutionFolders
|
||||
.Where(f => f.Parent is null)
|
||||
.Select(f => BuildFolderTree(f, solutionFilePath, vsSolution.SolutionFolders, vsSolution.SolutionProjects))
|
||||
.Select(f => GetSlnFolderModel(f, solutionFilePath, vsSolution.SolutionFolders, vsSolution.SolutionProjects))
|
||||
.ToList();
|
||||
|
||||
var rootProjects = vsSolution.SolutionProjects
|
||||
.Where(p => p.Parent is null)
|
||||
.Select(s => s.GetProjectModel(solutionFilePath))
|
||||
.ToList();
|
||||
|
||||
var solutionModel = new IntermediateSolutionModel
|
||||
{
|
||||
Name = Path.GetFileName(solutionFilePath),
|
||||
FilePath = solutionFilePath,
|
||||
Projects = vsSolution.SolutionProjects.Where(p => p.Parent is null).Select(s => new IntermediateProjectModel
|
||||
{
|
||||
Model = s,
|
||||
Id = s.Id,
|
||||
FullFilePath = new DirectoryInfo(Path.Join(Path.GetDirectoryName(solutionFilePath), s.FilePath)).FullName
|
||||
}).ToList(),
|
||||
Projects = rootProjects,
|
||||
SolutionFolders = rootFolders
|
||||
};
|
||||
return solutionModel;
|
||||
}
|
||||
|
||||
private static IntermediateSlnFolderModel BuildFolderTree(SolutionFolderModel folder, string solutionFilePath,
|
||||
private static IntermediateSlnFolderModel GetSlnFolderModel(SolutionFolderModel folder, string solutionFilePath,
|
||||
IReadOnlyList<SolutionFolderModel> allSolutionFolders, IReadOnlyList<SolutionProjectModel> allSolutionProjects)
|
||||
{
|
||||
var childFolders = allSolutionFolders
|
||||
.Where(f => f.Parent == folder)
|
||||
.Select(f => BuildFolderTree(f, solutionFilePath, allSolutionFolders, allSolutionProjects))
|
||||
.Select(f => GetSlnFolderModel(f, solutionFilePath, allSolutionFolders, allSolutionProjects))
|
||||
.ToList();
|
||||
|
||||
var projectsInFolder = allSolutionProjects
|
||||
.Where(p => p.Parent == folder)
|
||||
.Select(s => new IntermediateProjectModel
|
||||
{
|
||||
Model = s,
|
||||
Id = s.Id,
|
||||
FullFilePath = new DirectoryInfo(Path.Join(Path.GetDirectoryName(solutionFilePath), s.FilePath)).FullName
|
||||
})
|
||||
.Select(s => s.GetProjectModel(solutionFilePath))
|
||||
.ToList();
|
||||
|
||||
var filesInFolder = folder.Files?
|
||||
@@ -67,4 +62,14 @@ public static class IntermediateMapper
|
||||
Files = filesInFolder
|
||||
};
|
||||
}
|
||||
|
||||
private static IntermediateProjectModel GetProjectModel(this SolutionProjectModel project, string solutionFilePath)
|
||||
{
|
||||
return new IntermediateProjectModel
|
||||
{
|
||||
Model = project,
|
||||
Id = project.Id,
|
||||
FullFilePath = new DirectoryInfo(Path.Join(Path.GetDirectoryName(solutionFilePath), project.FilePath)).FullName
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using Ardalis.GuardClauses;
|
||||
using Microsoft.VisualStudio.SolutionPersistence.Model;
|
||||
using Microsoft.VisualStudio.SolutionPersistence.Serializer;
|
||||
|
||||
namespace SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user