/// <summary> /// Reads a given value from the ConfigNode. If a Subsection attribute is provided, this /// method will search in a subsection of the ConfigNode for the value /// </summary> /// <param name="node"></param> /// <param name="valueName"></param> /// <param name="attrs"></param> /// <returns></returns> private static string ReadValue(ConfigNode node, string valueName, System.Object[] attrs) { if (attrs == null) { attrs = new System.Object[] { } } ; Subsection ss = attrs.SingleOrDefault(attr => attr is Subsection) as Subsection; if (ss != null) { if (node.HasNode(ss.Section)) { node = node.GetNode(ss.Section); } else // uh oh, we expected a subsection .. { Log.Warning("ConfigUtil.ConfigNodeSerialization: Did not find a subsection called '{0}' when looking up value name {1}", ss.Section, valueName); } } return(node.ReadString(valueName)); } }
/// <summary> /// Writes the specified value string into a ConfigNode as a value named valueName. If any of /// the attributes are of Subsection, that value will be written into a subsection of the /// ConfigNode with name provided (will be created if necessary) /// </summary> /// <param name="node"></param> /// <param name="valueName"></param> /// <param name="value"></param> /// <param name="attrs"></param> private static void WriteValue(ConfigNode node, string valueName, string value, System.Object[] attrs) { if (attrs == null) { attrs = new System.Object[] { } } ; Subsection subsection = attrs.SingleOrDefault(attr => attr is Subsection) as Subsection; if (subsection != null) { //Log.Debug("valueName {0} with value '{1}' should be in a subsection called '{2}'", valueName, value, subsection.Section); if (node.HasNode(subsection.Section)) { //Log.Debug("Already has a section of that name"); node = node.GetNode(subsection.Section); } else { Log.Debug("Created a new section for " + subsection.Section); node = node.AddNode(subsection.Section); } } attrs.ToList().ForEach(attr => { if (attr is HelpDoc) { node.AddValue(string.Format("// {0}", valueName), ((HelpDoc)attr).Documentation); } }); node.AddValue(valueName, value); }