private void SynchronizeItems() { // Update existing values and create missing lines foreach (KeyValuePair <string, string> pair in this) { PropertyFileLine line = FindLine(pair.Key); if (line != null) { line.Value = pair.Value; } else { line = new PropertyFileLine(pair.Key, pair.Value, null); _lines.Add(line); } } // Remove lines mismatched with listed keys for (int index = _lines.Count - 1; index >= 0; index--) { PropertyFileLine line = _lines[index]; if (string.IsNullOrEmpty(line.Key) == false && this.ContainsKey(line.Key) == false) { _lines.RemoveAt(index); } } }
public void LoadFromStream(Stream stream) { _lines.Clear(); using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { PropertyFileLine line = new PropertyFileLine(reader.ReadLine()); _lines.Add(line); } } PopulateItems(); }