/// <summary> /// Deletes the Keyword "KeywordToDelete" from the ParentSection if it exists /// </summary> /// <param name="ParentSection"></param> /// <param name="SectionToDelete"></param> public static void SafeDeleteKeyword(PFSSection ParentSection, string KeywordToDelete) { PFSKeyword DeleteME = ParentSection.GetKeyword(KeywordToDelete, 1); if (DeleteME != null) { ParentSection.DeleteKeyword(DeleteME); } }
/// <summary> /// Example of different modifications to a PFS file, storing the result /// in a new file name /// </summary> /// <param name="filePath">File and path to the pfsExample.pfs file in the TestData folder</param> /// <param name="newFilePath">File and path to the new modified file</param> public static void ModifyPFSFile(string filePath, string newFilePath) { // Loading/Reading the file PFSFile pfsFile = new PFSFile(filePath, false); // Outmost section PFSSection target = pfsFile.GetTarget("Run11", 1); // Sub-section PFSSection section1 = target.GetSection("Results", 1); // Rename section section1.Name = "HDResults"; // Add another section after the HDResults section. The new section // is returned. PFSSection sectionRR = section1.InsertNewSection("RRResults", 2); // Add a keyword to the new section. The new keyword is returned. PFSKeyword kwOutid = sectionRR.InsertNewKeyword("outid", 1); // Add a parameter kwOutid.InsertNewParameterString("rr out", 1); // Add yet another keyword to the new section. The new keyword is returned. PFSKeyword kwFile = sectionRR.InsertNewKeyword("file", 2); // Add a parameter kwFile.InsertNewParameterFileName(@".\outputRR.res11", 1); PFSSection section2 = section1.GetSection("Result", 1); // Modify first parameter (string) of keyword section2.GetKeyword("outid", 1).GetParameter(1).ModifyStringParameter("hd out"); // Delete the first keyword in the outer-most section target.DeleteKeyword("key1", 1); // Write back file pfsFile.Write(newFilePath); }
/// <summary> /// Deletes the Keyword "KeywordToDelete" from the ParentSection if it exists /// </summary> /// <param name="ParentSection"></param> /// <param name="SectionToDelete"></param> public static void SafeDeleteKeyword(PFSSection ParentSection, string KeywordToDelete) { PFSKeyword DeleteME = ParentSection.GetKeyword(KeywordToDelete, 1); if (DeleteME != null) ParentSection.DeleteKeyword(DeleteME); }