Inheritance: IDisposable
Ejemplo n.º 1
0
        /// <summary>
        /// Returns a proper IniWriter depending upon the type parameter.
        /// </summary>
        private IniWriter GetIniWriter(TextWriter reader, IniFileType type)
        {
            IniWriter result = new IniWriter(reader);

            switch (type)
            {
            case IniFileType.Standard:
            case IniFileType.WindowsStyle:
                // do nothing
                break;

            case IniFileType.PythonStyle:
                result.AssignDelimiter  = ':';
                result.CommentDelimiter = '#';
                break;

            case IniFileType.SambaStyle:
            case IniFileType.MysqlStyle:
                result.AssignDelimiter  = '=';
                result.CommentDelimiter = '#';
                break;
            }

            return(result);
        }
Ejemplo n.º 2
0
 public void DisposeStringWriterNullReference()
 {
     StringWriter writer = new StringWriter ();
     IniWriter iniWriter = new IniWriter (writer);
     iniWriter.WriteSection ("Test");
     iniWriter.Dispose ();
 }
Ejemplo n.º 3
0
        /// <include file='IniDocument.xml' path='//Method[@name="SaveTextWriter"]/docs/*' />
        public void Save(TextWriter textWriter)
        {
            IniWriter  writer  = GetIniWriter(textWriter, fileType);
            IniItem    item    = null;
            IniSection section = null;

            foreach (string comment in initialComment)
            {
                writer.WriteEmpty(comment);
            }

            for (int j = 0; j < sections.Count; j++)
            {
                section = sections[j];
                writer.WriteSection(section.Name, section.Comment);
                for (int i = 0; i < section.ItemCount; i++)
                {
                    item = section.GetItem(i);
                    switch (item.Type)
                    {
                    case IniType.Key:
                        writer.WriteKey(item.Name, item.Value, item.Comment);
                        break;

                    case IniType.Empty:
                        writer.WriteEmpty(item.Comment);
                        break;
                    }
                }
            }

            writer.Close();
        }
Ejemplo n.º 4
0
        /// <include file='IniDocument.xml' path='//Method[@name="SaveTextWriter"]/docs/*' />
        public void Save(TextWriter textWriter)
        {
            IniWriter writer = new IniWriter (textWriter);
            IniItem item = null;
            IniSection section = null;

            foreach (string comment in initialComment)
            {
                writer.WriteEmpty  (comment);
            }

            for (int j = 0; j < sections.Count; j++)
            {
                section = sections[j];
                writer.WriteSection (section.Name, section.Comment);
                for (int i = 0; i < section.ItemCount; i++)
                {
                    item = section.GetItem (i);
                    switch (item.Type)
                    {
                    case IniType.Key:
                        writer.WriteKey (item.Name, item.Value, item.Comment);
                        break;
                    case IniType.Empty:
                        writer.WriteEmpty (item.Comment);
                        break;
                    }
                }
            }

            writer.Close ();
        }
Ejemplo n.º 5
0
		public void KeyWithIndentation ()
		{
			StringWriter writer = new StringWriter ();
			IniWriter iniWriter = new IniWriter (writer);
			
			iniWriter.Indentation = 2;
			iniWriter.WriteSection ("Required");
			iniWriter.WriteKey ("independence day", "july");
			Assert.AreEqual ("  independence day = july", ReadLine (writer, 2));
			iniWriter.Indentation = 0;
		}
Ejemplo n.º 6
0
		public void SectionWithoutComment ()
		{
			StringWriter writer = new StringWriter ();
			IniWriter iniWriter = new IniWriter (writer);
			
			Assert.AreEqual (IniWriteState.Start, iniWriter.WriteState);
			
			iniWriter.WriteSection ("Test Section");
			Assert.AreEqual ("[Test Section]", ReadLine (writer, 1));
			Assert.AreEqual (IniWriteState.Section, iniWriter.WriteState);
		}
Ejemplo n.º 7
0
		public void EmptyWithoutComment ()
		{
			StringWriter writer = new StringWriter ();
			IniWriter iniWriter = new IniWriter (writer);
			
			Assert.AreEqual (IniWriteState.Start, iniWriter.WriteState);
			
			iniWriter.WriteEmpty ();
			Assert.AreEqual ("", ReadLine (writer, 1));
			Assert.AreEqual (IniWriteState.BeforeFirstSection, iniWriter.WriteState);
		}
Ejemplo n.º 8
0
        public void FlushAndClose()
        {
            StringWriter writer = new StringWriter ();
            IniWriter iniWriter = new IniWriter (writer);

            iniWriter.WriteSection ("Required");
            iniWriter.WriteKey ("thanksgiving", "november 25th", "Football!");

            iniWriter.Close ();
            Assert.AreEqual (IniWriteState.Closed, iniWriter.WriteState);
        }
        public void KeyWithQuotesAndComment()
        {
            StringWriter writer = new StringWriter ();
            IniWriter iniWriter = new IniWriter (writer);

            iniWriter.UseValueQuotes = true;
            iniWriter.WriteSection ("Required");
            iniWriter.WriteKey ("thanksgiving", "November 25th", "Football!");
            iniWriter.UseValueQuotes = false;
            Assert.AreEqual ("thanksgiving = \"November 25th\" ; Football!",
                             ReadLine (writer, 2));
        }
Ejemplo n.º 10
0
		public void ReplaceEndOfLine ()
		{
			StringWriter writer = new StringWriter ();
			IniWriter iniWriter = new IniWriter (writer);
			
			iniWriter.WriteSection ("Required");
			iniWriter.WriteKey ("thanksgiving", "November\n 25th");
			
			Assert.AreEqual ("thanksgiving = November 25th", ReadLine (writer, 2));
		}
Ejemplo n.º 11
0
		public void NotOrderedWriteState ()
		{
			StringWriter writer = new StringWriter ();
			IniWriter iniWriter = new IniWriter (writer);
			
			iniWriter.WriteKey ("state", "Out of order");
		}
Ejemplo n.º 12
0
        /// <summary>
        /// Returns a proper IniWriter depending upon the type parameter.
        /// </summary>
        private IniWriter GetIniWriter(TextWriter reader, IniFileType type)
        {
            IniWriter result = new IniWriter (reader);

            switch (type)
            {
            case IniFileType.Standard:
            case IniFileType.WindowsStyle:
                // do nothing
                break;
            case IniFileType.PythonStyle:
                result.AssignDelimiter = ':';
                result.CommentDelimiter = '#';
                break;
            case IniFileType.SambaStyle:
            case IniFileType.MysqlStyle:
                result.AssignDelimiter = '=';
                result.CommentDelimiter = '#';
                break;
            }

            return result;
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Saves the current control bindings to an arbitrary stream.
 /// </summary>
 /// <param name="file">The writable stream to save to.</param>
 public void SaveConfiguration(Stream file)
 {
     using (IniWriter w = new IniWriter(file))
     {
         w.WriteSection("KeyBindings");
         rootcstate.WriteIni(w);
     }
 }
Ejemplo n.º 14
0
        private void WriteIni(IniWriter w, String ownns)
        {
            foreach (KeyValuePair<Keys, String> kvp in keycommands)
            {
                w.WriteKey(kvp.Key.ToString(), kvp.Value);
            }

            w.WriteEmpty();

            foreach (KeyValuePair<String, ControlState> kvp in children)
            {
                String childns = kvp.Key;
                if (ownns != null)
                    childns = String.Format("{0}.{1}", ownns, kvp.Key);

                w.WriteSection(String.Format("KeyBindings {0}", childns));
                kvp.Value.WriteIni(w, childns);
            }
        }
Ejemplo n.º 15
0
 public void WriteIni(IniWriter w)
 {
     WriteIni(w, null);
 }