/// <include file='IniSectionCollection.xml' path='//Method[@name="Add"]/docs/*' />
        public void Add(IniSection section)
        {
            if (list.Contains (section)) {
                throw new ArgumentException ("IniSection already exists");
            }

            list.Add (section.Name, section);
        }
Esempio n. 2
0
		/// <summary>
		/// Loads the file not saving comments.
		/// </summary>
		private void LoadReader (IniReader reader)
		{
			reader.IgnoreComments = false;
			bool sectionFound = false;
			IniSection section = null;
			
			try {
				while (reader.Read ())
				{
					switch (reader.Type)
					{
					case IniType.Empty:
						if (!sectionFound) {
							initialComment.Add (reader.Comment);
						} else {
							section.Set (reader.Comment);
						}

						break;
					case IniType.Section:
						sectionFound = true;
						// If section already exists then overwrite it
						if (sections[reader.Name] != null) {
							sections.Remove (reader.Name);
						}
						section = new IniSection (reader.Name, reader.Comment);
						sections.Add (section);

						break;
					case IniType.Key:
						if (section.GetValue (reader.Name) == null) { 
							section.Set (reader.Name, reader.Value, reader.Comment); 
						} 
						break;
					}
				}
			} catch (Exception ex) {
				throw ex;
			} finally {
				// Always close the file
				reader.Close ();
			}
		}
Esempio n. 3
0
        /// <summary>
        /// Merges all of the configs from the config collection into the 
        /// IniDocument before it is saved.  
        /// </summary>
        private void MergeConfigsIntoDocument()
        {
            RemoveSections ();
            foreach (IConfig config in this.Configs)
            {
                string[] keys = config.GetKeys ();

                // Create a new section if one doesn't exist
                if (iniDocument.Sections[config.Name] == null) {
                    IniSection section = new IniSection (config.Name);
                    iniDocument.Sections.Add (section);
                }
                RemoveKeys (config.Name);

                for (int i = 0; i < keys.Length; i++)
                {
                    iniDocument.Sections[config.Name].Set (keys[i], config.Get (keys[i]));
                }
            }
        }
 /// <include file='IniSectionCollection.xml' path='//Method[@name="CopyToStrong"]/docs/*' />
 public void CopyTo(IniSection[] array, int index)
 {
     ((ICollection)list).CopyTo (array, index);
 }