/// <summary> /// Try Get Value /// </summary> public bool TryGetValue(string name, out NameValueRecord record) { if (m_Records.TryGetValue(name, out record)) { return(true); } record = null; return(false); }
/// <summary> /// Add /// </summary> public NameValueRecord Add(NameValueRecord item) { if (null == item) { throw new ArgumentNullException(nameof(item)); } CoreAddRecord(item); return(item); }
internal void CoreRemoveRecord(NameValueRecord record) { if (null == record) { return; } if (record.Owner != this) { return; } m_Records.Remove(record.Name); record.Owner = null; }
/// <summary> /// Load /// </summary> public static NameValueDocument Load(IEnumerable <string> lines, StringComparer comparer, IniFileCommentKind commentKind) { if (null == lines) { throw new ArgumentNullException(nameof(lines)); } NameValueDocument result = new NameValueDocument(comparer, commentKind); List <string> comments = new List <string>(); int index = 0; foreach (string line in lines.Select(x => x.Trim())) { index += 1; if (string.IsNullOrWhiteSpace(line)) { continue; } if (line.StartsWith(";") || line.StartsWith("#")) { comments.Add(line.Substring(1)); continue; } if (NameValueRecord.TryParse(line, out var record)) { record.Comments = string.Join(Environment.NewLine, comments); comments.Clear(); result.Add(record); } else { throw new FormatException($"Syntax error in line {index}"); } } return(result); }
internal void CoreAddRecord(NameValueRecord record) { if (null == record) { return; } if (record.Owner == this) { return; } if (record.Owner != null) { record.Owner.CoreRemoveRecord(record); } if (m_Records.TryGetValue(record.Name, out var old)) { old.Owner.CoreRemoveRecord(old); } m_Records.Add(record.Name, record); }