private static bool EditJson(string strFileText, SearchFileEditorConfig.EditFileInfo pFileInfo, out string strFileTextNew) { strFileTextNew = ""; JObject pRootObject = JObject.Parse(strFileText); JToken pField = pRootObject.SelectToken(pFileInfo.FieldName); if (pField == null) { Console.WriteLine($"Run Json Error // NotFound Field : {pFileInfo.FieldName}"); return(false); } pRootObject.SelectToken(pFileInfo.FieldName)?.Replace(pFileInfo.Value); strFileTextNew = pRootObject.ToString(Formatting.Indented); return(true); }
private static void EditYAML(string strFilePath, string strFileText, SearchFileEditorConfig.EditFileInfo pFileInfo) { StringReader pStrReader = new StringReader(strFileText); var yaml = new YamlStream(); yaml.Load(pStrReader); YamlMappingNode pRootObject = (YamlMappingNode)yaml.Documents[0].RootNode; YamlNode pObject = pRootObject; Queue <string> queueField = new Queue <string>(pFileInfo.FieldName.Split(".")); while (queueField.TryDequeue(out string strFieldName)) { YamlMappingNode pObjectParsed = (YamlMappingNode)pObject; if (pObjectParsed == null) { Console.WriteLine("Run YAML Error"); return; } if (pObjectParsed.Children.TryGetValue(strFieldName, out pObject) == false) { Console.WriteLine("Run YAML Error"); return; } if (queueField.Count == 0) { pObjectParsed.Children[strFieldName] = pFileInfo.Value; } } StreamWriter pWriter = new StreamWriter(strFilePath); yaml.Save(pWriter); pStrReader.Close(); pStrReader.Dispose(); pWriter.Close(); pWriter.Dispose(); }