Amazon.Runtime.Internal.Util.IniFile.EditSection C# (CSharp) Метод

EditSection() публичный Метод

Update the section with the properties given. If the section doesn't exist, it will be appended to the file. -Any properties that do exist in the section will be updated. -A null value for a property denotes that it should be deleted from the section -If any properties don't exist they will be appended to the end of the section in the same order they appear in the list.
public EditSection ( string sectionName, string>.List properties ) : void
sectionName string name of the section to operate on
properties string>.List ordered list of properties to add/update/delete
Результат void
        public void EditSection(string sectionName, List<KeyValuePair<string, string>> properties)
        {
            EnsureSectionExists(sectionName);

            // build dictionary from list
            // ensure the keys will be looked up case-insensitive
            var propertiesLookup = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            foreach (var pair in properties)
            {
                propertiesLookup.Add(pair.Key, pair.Value);
            }

            var lineNumber = 0;
            if (TrySeekSection(sectionName, ref lineNumber))
            {
                lineNumber++;
                string propertyName;
                string propertyValue;
                while (SeekProperty(ref lineNumber, out propertyName, out propertyValue))
                {
                    var propertyDeleted = false;
                    if (propertiesLookup.ContainsKey(propertyName))
                    {
                        if (!string.Equals(propertiesLookup[propertyName], propertyValue))
                        {
                            if (propertiesLookup[propertyName] == null)
                            {
                                // delete the line
                                Lines.RemoveAt(lineNumber);
                                propertyDeleted = true;
                            }
                            else
                            {
                                // update the line
                                Lines[lineNumber] = propertyName + keyValueSeparator + propertiesLookup[propertyName];
                            }
                        }
                        propertiesLookup.Remove(propertyName);
                    }
                    if (!propertyDeleted)
                    {
                        lineNumber++;
                    }
                }
                foreach (var pair in properties)
                {
                    if (propertiesLookup.ContainsKey(pair.Key))
                    {
                        Lines.Insert(lineNumber++, pair.Key + keyValueSeparator + pair.Value);
                    }
                }
            }
        }