Exemple #1
0
        /// <summary>
        /// Gets a section from the <see cref="IniContainer"/> or adds
        /// a new section if none exists.
        /// </summary>
        /// <param name="container">The container to use</param>
        /// <param name="name">The section name</param>
        /// <returns>The section instance</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        public static IniSection GetOrAddSection(this IniContainer container, string name)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Value cannot be whitespace.", nameof(name));
            }

            var section = container.GetSection(name);

            if (section != null)
            {
                return(section);
            }

            section = new IniSection(name);
            container.Sections.Add(section);

            return(section);
        }