MonoDevelop.Projects.Project.AddDirectory C# (CSharp) Method

AddDirectory() public method

Adds a directory to the project.
The directory is created if it doesn't exist
public AddDirectory ( string relativePath ) : ProjectFile
relativePath string /// Relative path of the directory. ///
return ProjectFile
		public ProjectFile AddDirectory (string relativePath)
		{
			string newPath = Path.Combine (BaseDirectory, relativePath);

			foreach (ProjectFile fInfo in Files)
				if (fInfo.Name == newPath && fInfo.Subtype == Subtype.Directory)
					return fInfo;

			if (!Directory.Exists (newPath)) {
				if (File.Exists (newPath)) {
					string message = GettextCatalog.GetString ("Cannot create directory {0}, as a file with that name exists.", newPath);
					throw new InvalidOperationException (message);
				}
				FileService.CreateDirectory (newPath);
			}

			ProjectFile newDir = new ProjectFile (newPath);
			newDir.Subtype = Subtype.Directory;
			AddFile (newDir);
			return newDir;
		}
		

Usage Example

Esempio n. 1
0
        public async Task GetParentFileTest(string inputFile, string expectedParentFile)
        {
            string   solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            Project p   = (Project)sol.Items [0];
            var     dir = p.BaseDirectory;

            string inputFileDestination  = Path.Combine(dir, "FileNesting", inputFile);
            string parentFileDestination = Path.Combine(dir, "FileNesting", expectedParentFile);

            p.AddDirectory("FileNesting");
            p.AddFile(inputFileDestination);
            p.AddFile(parentFileDestination);

            string parentFile = FileNestingService.GetParentFile(p, inputFileDestination);

            Assert.That(parentFile, Is.EqualTo(parentFileDestination), $"Was expecting parent file {parentFileDestination} for {inputFileDestination} but got {parentFile}");

            // Now check we get nothing when parent file doesn't exist
            p.Files.Remove(parentFileDestination);
            parentFile = FileNestingService.GetParentFile(p, inputFileDestination);
            Assert.Null(parentFile, $"Was expecting no parent file for {inputFileDestination} but got {parentFile}");

            sol.Dispose();
        }
All Usage Examples Of MonoDevelop.Projects.Project::AddDirectory