Пример #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SectionData"/> class.
        /// </summary>
        public SectionData(string sectionName, IEqualityComparer <string> searchComparer)
        {
            _searchComparer = searchComparer;

            if (string.IsNullOrEmpty(sectionName))
            {
                throw new ArgumentException("section name can not be empty");
            }

            _leadingComments   = new List <string>();
            _keyDataCollection = new KeyDataCollection(_searchComparer);
            SectionName        = sectionName;
        }
Пример #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KeyDataCollection" class
 ///     from a previous instance of <see cref="KeyDataCollection".
 /// </summary>
 /// <remarks>
 ///     Data from the original KeyDataCollection instance is deeply copied
 /// </remarks>
 /// <param name="ori">
 ///     The instance of the <see cref="KeyDataCollection" class
 ///     used to create the new instance.
 /// </param>
 public KeyDataCollection(KeyDataCollection ori, IEqualityComparer <string> searchComparer)
     : this(searchComparer)
 {
     foreach (var key in ori)
     {
         if (keyData.ContainsKey(key.KeyName))
         {
             keyData[key.KeyName] = (KeyData)key.Clone();
         }
         else
         {
             keyData.Add(key.KeyName, (KeyData)key.Clone());
         }
     }
 }
Пример #3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KeyDataCollection"/> class
 ///     from a previous instance of <see cref="KeyDataCollection"/>.
 /// </summary>
 /// <remarks>
 ///     Data from the original KeyDataCollection instance is deeply copied
 /// </remarks>
 /// <param name="ori">
 ///     The instance of the <see cref="KeyDataCollection"/> class
 ///     used to create the new instance.
 /// </param>
 public KeyDataCollection(KeyDataCollection ori, IEqualityComparer <string> searchComparer)
     : this(searchComparer)
 {
     foreach (KeyData key in ori)
     {
         if (_keyData.ContainsKey(key.KeyName))
         {
             _keyData[key.KeyName] = key;
         }
         else
         {
             _keyData.Add(key.KeyName, key);
         }
     }
 }
Пример #4
0
        private void WriteKeyValueData(KeyDataCollection keyDataCollection, StringBuilder sb)
        {
            foreach (KeyData keyData in keyDataCollection)
            {
                // Add a blank line if the key value pair has comments
                if (keyData.Comments.Count > 0)
                {
                    sb.AppendLine();
                }

                // Write key comments
                WriteComments(keyData.Comments, sb);

                //Write key and value
                sb.AppendLine(string.Format("{0}{3}{1}{3}{2}", keyData.KeyName, Configuration.KeyValueAssigmentChar, keyData.Value, Configuration.AssigmentSpacer));
            }
        }
Пример #5
0
 /// <summary>
 ///     Initializes a new IniData instance using a previous
 ///     <see cref="SectionDataCollection"/>.
 /// </summary>
 /// <param name="sdc">
 ///     <see cref="SectionDataCollection"/> object containing the
 ///     data with the sections of the file
 /// </param>
 public IniData(SectionDataCollection sdc)
 {
     _sections           = (SectionDataCollection)sdc.Clone();
     Global              = new KeyDataCollection();
     SectionKeySeparator = '.';
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SectionData"/> class
 /// from a previous instance of <see cref="SectionData"/>.
 /// </summary>
 /// <remarks>
 /// Data is deeply copied
 /// </remarks>
 /// <param name="ori">
 /// The instance of the <see cref="SectionData"/> class
 /// used to create the new instance.</param>
 public SectionData(SectionData ori)
 {
     _comments          = new List <string>(ori._comments);
     _keyDataCollection = new KeyDataCollection(ori._keyDataCollection);
 }
Пример #7
0
 /// <summary>
 /// Initializes a new IniData instance using a previous
 /// <see cref="SectionDataCollection"/>.
 /// </summary>
 /// <param name="sdc">
 /// <see cref="SectionDataCollection"/> object containing the
 /// data with the sections of the file</param>
 public IniData(SectionDataCollection sdc)
 {
     _sections = (SectionDataCollection)sdc.Clone();
     Global    = new KeyDataCollection();
 }
Пример #8
0
 /// <summary>
 ///     Initializes a new IniData instance using a previous
 ///     <see cref="SectionDataCollection" />.
 /// </summary>
 /// <param name="sdc">
 ///     <see cref="SectionDataCollection" /> object containing the
 ///     data with the sections of the file
 /// </param>
 public IniDataCaseInsensitive(SectionDataCollection sdc)
     : base(new SectionDataCollection(sdc, StringComparer.OrdinalIgnoreCase))
 {
     Global = new KeyDataCollection(StringComparer.OrdinalIgnoreCase);
 }
Пример #9
0
        public bool TryGetKey(string key, out string value)
        {
            value = string.Empty;
            bool flag = string.IsNullOrEmpty(key);
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                string[] array = key.Split(new char[]
                {
                    this.SectionKeySeparator
                });
                int  num   = array.Length - 1;
                bool flag2 = num > 1;
                if (flag2)
                {
                    throw new ArgumentException("key contains multiple separators", "key");
                }
                bool flag3 = num == 0;
                if (flag3)
                {
                    bool flag4 = !this.Global.ContainsKey(key);
                    if (flag4)
                    {
                        result = false;
                    }
                    else
                    {
                        value  = this.Global[key];
                        result = true;
                    }
                }
                else
                {
                    string text = array[0];
                    key = array[1];
                    bool flag5 = !this._sections.ContainsSection(text);
                    if (flag5)
                    {
                        result = false;
                    }
                    else
                    {
                        KeyDataCollection keyDataCollection = this._sections[text];
                        bool flag6 = !keyDataCollection.ContainsKey(key);
                        if (flag6)
                        {
                            result = false;
                        }
                        else
                        {
                            value  = keyDataCollection[key];
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }