/// @brief Add empty key to section /// /// @param key_name name of key /// @retval reference to related key public IniKey AddKey(string key_name) { int id; IniSection.IniKey key; key_name = key_name.Trim(); key = null; if (key_name.Length != 0) { id = _Keys_Array.IndexOf(key_name); if (id == -1) { key = new IniSection.IniKey(this, key_name); _Keys_Array.Add(key); } else { key = (IniKey)_Keys_Array[id]; } } return(key); }
// Adds a key to the IniSection object, returns a IniKey object to the new or existing object public IniKey AddKey(string sKey, object value = null) { sKey = (sKey + "").Trim(); IniSection.IniKey k = null; if (sKey.Length != 0) { sKey = sKey .Replace("\r\n", "┘") .Replace("\n", "┘") .Replace("[", "┤") .Replace("]", "├"); if (m_keys.ContainsKey(sKey)) { k = (IniKey)m_keys[sKey]; } else { k = new IniSection.IniKey(this, sKey); m_keys[sKey] = k; m_pIniFile.changed = true; } if (value != null) { k.SetValue(value + ""); } } return(k); }
// Returns a KeyValue in a certain section public string GetKeyValue(string sSection, string sKey) { IniSection s = GetSection(sSection); IniSection.IniKey k = s?.GetKey(sKey); if (k != null) { return k.Value; } return string.Empty; }
// Sets a KeyValuePair in a certain section public bool SetKeyValue(string sSection, string sKey, string sValue) { IniSection s = AddSection(sSection); IniSection.IniKey k = s?.AddKey(sKey); if (k != null) { k.Value = sValue; return true; } return false; }
public void Save(string sFileName) { IEnumerator enumerator; StreamWriter writer = new StreamWriter(sFileName, false); try { enumerator = this.Sections.GetEnumerator(); while (enumerator.MoveNext()) { IEnumerator enumerator2; IniSection current = (IniSection)enumerator.Current; Trace.WriteLine($"Writing Section: [{current.Name}]"); writer.WriteLine($"[{current.Name}]"); try { enumerator2 = current.Keys.GetEnumerator(); while (enumerator2.MoveNext()) { IniSection.IniKey key = (IniSection.IniKey)enumerator2.Current; if (key.Value != string.Empty) { Trace.WriteLine($"Writing Key: {key.Name}={key.Value}"); writer.WriteLine($"{key.Name}={key.Value}"); } else { Trace.WriteLine($"Writing Key: {key.Name}"); writer.WriteLine($"{key.Name}"); } } continue; } finally { if (enumerator2 is IDisposable) { (enumerator2 as IDisposable).Dispose(); } } } } finally { if (enumerator is IDisposable) { (enumerator as IDisposable).Dispose(); } } writer.Close(); }
// Renames an existing key returns true on success, false if the key didn't exist or there was another section with the same sNewKey public bool RenameKey(string sSection, string sKey, string sNewKey) { // Note string trims are done in lower calls. IniSection s = GetSection(sSection); if (s != null) { IniSection.IniKey k = s.GetKey(sKey); if (k != null) { return k.SetName(sNewKey); } } return false; }
public string GetKeyValue(string sSection, string sKey) { IniSection section = this.GetSection(sSection); if (section != null) { IniSection.IniKey key = section.GetKey(sKey); if (key != null) { return(key.Value); } } return(string.Empty); }
public bool RenameKey(string sSection, string sKey, string sNewKey) { IniSection section = this.GetSection(sSection); if (section != null) { IniSection.IniKey key = section.GetKey(sKey); if (key != null) { return(key.SetName(sNewKey)); } } return(false); }
// Returns a KeyValue in a certain section public string GetKeyValue(string sSection, string sKey) { IniSection s = GetSection(sSection); if (s != null) { IniSection.IniKey k = s.GetKey(sKey); if (k != null) { return(k.Value); } } return(String.Empty); }
public string GetString(string sSection, string sKey, string def = "") { IniSection s = GetSection(sSection); if (s != null) { IniSection.IniKey k = s.GetKey(sKey); if (k != null) { return(k.Value); } } return(def); }
public bool SetKeyValue(string sSection, string sKey, string sValue) { IniSection section = this.AddSection(sSection); if (section != null) { IniSection.IniKey key = section.AddKey(sKey); if (key != null) { key.Value = sValue; return(true); } } return(false); }
/// <summary> /// Returns a KeyValue in a certain section /// </summary> /// <param name="section"></param> /// <param name="key"></param> /// <returns></returns> public string GetKeyValue(string section, string key) { IniSection s = GetSection(section); if (s == null) { return(string.Empty); } IniSection.IniKey k = s.GetKey(key); if (k == null) { return(string.Empty); } return(k.Value); }
/// <summary> /// Renames an existing key /// </summary> /// <param name="section"></param> /// <param name="key"></param> /// <param name="newKey"></param> /// <returns>returns true on success, false if the key didn't exist or there was another section with the same sNewKey</returns> public bool RenameKey(string section, string key, string newKey) { // Note string trims are done in lower calls. IniSection s = GetSection(section); if (s == null) { return(false); } IniSection.IniKey k = s.GetKey(key); if (k == null) { return(false); } return(k.SetName(newKey)); }
// Adds a key to the IniSection object, returns a IniKey object to the new or existing object public IniKey AddKey(string sKey) { sKey = sKey.Trim(); IniSection.IniKey k = null; if (sKey.Length != 0) { if (m_keys.ContainsKey(sKey)) { k = (IniKey)m_keys[sKey]; } else { k = new IniSection.IniKey(this, sKey); m_keys[sKey] = k; } } return(k); }
/// <summary> /// Sets a KeyValuePair in a certain section /// </summary> /// <param name="section"></param> /// <param name="key"></param> /// <param name="value"></param> /// <returns></returns> public bool SetKeyValue(string section, string key, string value) { IniSection s = AddSection(section); if (s == null) { return(false); } IniSection.IniKey k = s.AddKey(key); if (k == null) { return(false); } k.Value = value; return(true); }
// Sets a KeyValuePair in a certain section public bool SetKeyValue(string sSection, string sKey, string sValue) { IniSection s = AddSection(sSection); if (s != null) { IniSection.IniKey k = s.AddKey(sKey); if (k != null) { if (k.Value != sValue) { k.Value = sValue; changed = true; } return(true); } } return(false); }
// Returns a KeyValue in a certain section public string GetKeyValue(string sSection, string sKey, string DefaultValue = "") { IniSection s = GetSection(sSection); if (s != null) { IniSection.IniKey k = s.GetKey(sKey); if (k != null) { return(k.Value); } else { return(DefaultValue); } } return(DefaultValue); }
// Sets a KeyValuePair in a certain section public bool SetKeyValue(string sSection, string sKey, string sValue, string DefaultValue = "") { IniSection s = AddSection(sSection); if (s != null) { IniSection.IniKey k = s.AddKey(sKey); if (k != null) { k.Value = sValue; return(true); } else { k.Value = DefaultValue; } } return(false); }
public bool ForceRenameKey(string sSection, string sKey, string sNewKey) { // Note string trims are done in lower calls. IniSection s = GetSection(sSection); if (s != null) { IniSection.IniKey k = s.GetKey(sKey); if (k != null) { return(k.ForceSetName(sNewKey)); } if (sKey.Length == 0) { s.AddKey(sNewKey); return(true); } } return(false); }
// Adds a key to the IniSection object, returns a IniKey object to the new or existing object public IniKey AddKey(string sKey) { sKey = sKey.Trim(); IniSection.IniKey k = null; if (sKey.Length != 0) { if (m_keys.ContainsKey(sKey)) { k = (IniKey)m_keys[sKey]; } else { k = new IniSection.IniKey(this, sKey); m_keys[sKey] = k; } } return k; }