2017-06-05 12:20:39 +00:00
|
|
|
|
using System;
|
2017-06-07 21:02:29 +00:00
|
|
|
|
using System.Collections;
|
2017-06-05 12:20:39 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2017-07-22 19:27:41 +00:00
|
|
|
|
namespace Glove.INI {
|
2017-06-07 21:02:29 +00:00
|
|
|
|
public class Instance : IEnumerable<KeyValuePair<string, Value>> {
|
|
|
|
|
private Dictionary<string, Value> Data
|
|
|
|
|
= new Dictionary<string, Value>(StringComparer.OrdinalIgnoreCase);
|
2017-06-06 21:13:25 +00:00
|
|
|
|
|
2017-06-07 21:02:29 +00:00
|
|
|
|
internal Instance() { }
|
2017-06-05 12:20:39 +00:00
|
|
|
|
|
2017-06-07 21:02:29 +00:00
|
|
|
|
internal void Push(string line) {
|
|
|
|
|
if(line.Contains('=')) {
|
|
|
|
|
var parts = line.Split(new char[] { '=' }, 2);
|
|
|
|
|
Data.Add(parts[0].Trim(), new Value(parts[1].Trim()));
|
|
|
|
|
} else
|
|
|
|
|
throw new FormatException("Line is not a key-value pair delimited by an equals sign.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Value this[string key] {
|
|
|
|
|
get {
|
|
|
|
|
if(Data.ContainsKey(key))
|
|
|
|
|
return Data[key];
|
|
|
|
|
else return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ContainsKey(string key) {
|
|
|
|
|
return Data.ContainsKey(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() {
|
|
|
|
|
return Data.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator<KeyValuePair<string, Value>> IEnumerable<KeyValuePair<string, Value>>.GetEnumerator() {
|
|
|
|
|
return Data.GetEnumerator();
|
|
|
|
|
}
|
2017-06-05 12:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|