/// <summary> /// Adds a key to a section to the document. /// </summary> /// <param name="section"> /// The section. /// </param> /// <param name="key"> /// The key to add. /// </param> /// <param name="create"> /// Create section if it does not exist? /// </param> /// <param name="replace"> /// Replace other key on name conflict. /// </param> /// <returns> /// True if the key was added to the document section and false otherwise. /// </returns> public bool Add(string section, Key key, bool create = true, bool replace = false) { if (key == null || !Naming.IsValid(key.Name) || !Naming.IsValid(section)) { return(false); } if (!Contains(section)) { if (!create) { return(false); } if (!Add(new Section(section))) { return(false); } } return(m_sections[section].Add(key, replace)); }
/// <summary> /// Add a section to the document. /// </summary> /// <param name="section"> /// The section to add. /// </param> /// <param name="replace"> /// Replace other section on name conflict. /// </param> /// <returns> /// True if the section was added to the document and false otherwise. /// </returns> public bool Add(Section section, bool replace = false) { if (section == null || !Naming.IsValid(section.Name)) { return(false); } if (Contains(section.Name)) { if (!replace) { return(false); } m_sections[section.Name] = section; } else { m_sections.Add(section.Name, section); } return(true); }
/// <summary> /// Adds a key to the section. /// </summary> /// <param name="key"> /// The key to add. /// </param> /// <param name="replace"> /// If the given key should overwrite keys with the same name. /// </param> /// <returns> /// True if the key was sucessfully added to the section and false /// otherwise. /// </returns> public bool Add(Key key, bool replace = false) { if (key == null || !Naming.IsValid(key.Name)) { return(false); } if (Contains(key.Name)) { if (!replace) { return(false); } m_keys[key.Name] = key; } else { m_keys.Add(key.Name, key); } return(true); }
/// <summary> /// Constructs the section with an optional name. /// </summary> /// <param name="name"> /// The name of the section. /// </param> public Section(string name = null) { m_name = Naming.IsValid(name) ? name : null; m_keys = new Dictionary <string, Key>(); }
/// <summary> /// Constructs the instance with an optional name and value. /// </summary> /// <remarks> /// <para> /// If the given name is invalid, <see cref="Name"/> will be set to /// <see cref="string.Empty"/> (See <see cref="Naming.IsValid(string)"/>). /// </para> /// <para> /// If the given value is null, <see cref="Value"/> will be set to /// <see cref="string.Empty"/>. /// </para> /// </remarks> /// <param name="name"> /// The name of the key. /// </param> /// <param name="value"> /// The value of the key. /// </param> public Key(string name = null, string value = null) { m_name = Naming.IsValid(name) ? name : string.Empty; Value = value ?? string.Empty; }