本文整理汇总了C#中SolutionFolder.AddSolutionFolder方法的典型用法代码示例。如果您正苦于以下问题:C# SolutionFolder.AddSolutionFolder方法的具体用法?C# SolutionFolder.AddSolutionFolder怎么用?C# SolutionFolder.AddSolutionFolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SolutionFolder
的用法示例。
在下文中一共展示了SolutionFolder.AddSolutionFolder方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addFilesToSolution
public void addFilesToSolution(Project solutionFolderProject, SolutionFolder solutionFolder, string basePath)
{
//For each file, add to the folder
foreach (var file in Directory.EnumerateFiles(basePath))
{
//Add the file as a copy into the solution folder
solutionFolderProject.ProjectItems.AddFromFileCopy(file);
}
//for each directory, create a new solution folder and add the files
foreach (var dir in Directory.EnumerateDirectories(basePath))
{
//Create a new solution folder and return a Project object
Project folderProject = solutionFolder.AddSolutionFolder(Path.GetFileName(dir));
//Cast the Project object to a SolutionFolder to be able to create more Solution Folders children
SolutionFolder solFolder = (SolutionFolder)folderProject.Object;
//Call the function to add the original files to the solution folder
addFilesToSolution(folderProject, solFolder, dir);
}
}
示例2: AddSolutionFolder
private void AddSolutionFolder(SolutionFolder parent, SolutionFolderTemplate solutionFolder,
IList<Project> projects, SolutionDataViewModel solutionData)
{
if (!solutionData.CreateTests &&
parent == null &&
solutionFolder.Name == "Tests")
{
return;
}
if (!solutionData.CreateFakes &&
solutionFolder.Name == "Fake")
{
return;
}
var addedProject = parent == null
? GetSolution().AddSolutionFolder(solutionFolder.Name)
: parent.AddSolutionFolder(solutionFolder.Name);
foreach (var item in solutionFolder.Items)
{
AddProjectToSolution(addedProject.Object as SolutionFolder, item, projects, solutionData);
}
}
示例3: CreateSolutionFolder
private void CreateSolutionFolder(
SolutionFolder solutionFolder,
SolutionFolderData solutionFolderData,
Action<double> progressAction,
SolutionDataViewModel solutionData,
CancellationToken ct)
{
if (!solutionData.CreateTests &&
solutionFolder == null &&
solutionFolderData.Name == "Tests")
{
return;
}
if (!solutionData.CreateFakes &&
solutionFolderData.Name == "Fake")
{
return;
}
var addedProject = solutionFolder == null
? GetSolution().AddSolutionFolder(solutionFolderData.Name)
: solutionFolder.AddSolutionFolder(solutionFolderData.Name);
if (solutionFolderData.Items.Length == 0)
{
return;
}
SolutionFolder subFolder = addedProject.Object as SolutionFolder;
var k = 1.0/solutionFolderData.Items.Length;
for (int i = 0; i < solutionFolderData.Items.Length; ++i)
{
var pr = k*i;
progressAction(pr);
int j = i;
CreateSolutionItem(
subFolder,
solutionFolderData.Items[i], progress =>
{
pr = k*j + progress*k;
progressAction(pr);
},
solutionData,
ct);
ct.ThrowIfCancellationRequested();
}
}
示例4: AddProjectItemsToSolution
protected internal virtual void AddProjectItemsToSolution(SolutionFolder solutionFolder, IEnumerable<ProjectItem> projectItems, string sourceDirectoryPath, string destinationDirectoryPath)
{
if(solutionFolder == null)
throw new ArgumentNullException("solutionFolder");
if(projectItems == null)
throw new ArgumentNullException("projectItems");
foreach(var projectItem in projectItems)
{
if(projectItem.IsPhysicalFolder())
{
var childItem = solutionFolder.Parent.ProjectItems.Cast<ProjectItem>().FirstOrDefault(item => string.Equals(item.Name, projectItem.Name, StringComparison.OrdinalIgnoreCase));
// ReSharper disable ConvertIfStatementToNullCoalescingExpression
if(childItem == null)
childItem = solutionFolder.AddSolutionFolder(projectItem.Name).ParentProjectItem;
// ReSharper restore ConvertIfStatementToNullCoalescingExpression
SolutionFolder childSolutionFolder = null;
if(childItem.SubProject != null)
childSolutionFolder = childItem.SubProject.Object as SolutionFolder;
if(childSolutionFolder == null)
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The project-item \"{0}\" already exists but is not a solution-folder.", childItem.Name));
this.AddProjectItemsToSolution(childSolutionFolder, projectItem.ProjectItems.Cast<ProjectItem>(), this.FileSystem.Path.Combine(sourceDirectoryPath, projectItem.Name), this.FileSystem.Path.Combine(destinationDirectoryPath, projectItem.Name));
}
else
{
this.AddProjectItemToSolutionPhysicallyIfNecessary(projectItem, sourceDirectoryPath, destinationDirectoryPath);
var itemAlreadyExists = solutionFolder.Parent.ProjectItems.Cast<ProjectItem>().Any(item => string.Equals(item.Name, projectItem.Name, StringComparison.OrdinalIgnoreCase));
if(itemAlreadyExists)
continue;
var filesToDelete = new List<FileInfoBase>();
var destinationFilePath = this.FileSystem.Path.Combine(destinationDirectoryPath, projectItem.Name);
if(!this.FileSystem.File.Exists(destinationFilePath))
{
var file = this.FileSystem.FileInfo.FromFileName(destinationFilePath);
if(!file.Directory.Exists)
file.Directory.Create();
using(this.FileSystem.File.Create(destinationFilePath)) {}
filesToDelete.Add(file);
}
solutionFolder.Parent.ProjectItems.AddFromFile(destinationFilePath);
var document = this.DevelopmentToolsEnvironment.Documents.Cast<Document>().FirstOrDefault(item => string.Equals(item.FullName, destinationFilePath, StringComparison.OrdinalIgnoreCase));
if(document != null)
document.Close();
foreach(var item in filesToDelete)
{
var directory = item.Directory;
if(item.Exists)
item.Delete();
if(!directory.GetFileSystemInfos().Any())
directory.Delete();
}
}
}
}