forked from Enichan/Ini
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ini.cs
1060 lines (941 loc) · 29.9 KB
/
Ini.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//ref https://github.com/Enichan/Ini
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public struct IniValue
{
private static bool TryParseInt(string text, out int value)
{
int res;
if (Int32.TryParse(text,
System.Globalization.NumberStyles.Integer,
System.Globalization.CultureInfo.InvariantCulture,
out res))
{
value = res;
return true;
}
value = 0;
return false;
}
private static bool TryParseDouble(string text, out double value)
{
double res;
if (Double.TryParse(text,
System.Globalization.NumberStyles.Float,
System.Globalization.CultureInfo.InvariantCulture,
out res))
{
value = res;
return true;
}
value = Double.NaN;
return false;
}
public string Comment;
public string Value;
public IniValue(object value)
{
Comment = null;
var formattable = value as IFormattable;
if (formattable != null)
{
Value = formattable.ToString(null, System.Globalization.CultureInfo.InvariantCulture);
}
else
{
Value = value != null ? value.ToString() : null;
}
}
public IniValue(string value)
{
Value = value;
Comment = null;
}
public bool AsBool { get { return ToBool(); } }
public bool ToBool(bool valueIfInvalid = false)
{
bool res;
if (TryConvertBool(out res))
{
return res;
}
return valueIfInvalid;
}
public bool TryConvertBool(out bool result)
{
if (Value == null)
{
result = default(bool);
return false;
}
var boolStr = Value.Trim().ToLowerInvariant();
if (boolStr == "true")
{
result = true;
return true;
}
else if (boolStr == "false")
{
result = false;
return true;
}
result = default(bool);
return false;
}
public int AsInt { get { return ToInt(); } }
public int ToInt(int valueIfInvalid = 0)
{
int res;
if (TryConvertInt(out res))
{
return res;
}
return valueIfInvalid;
}
public bool TryConvertInt(out int result)
{
if (Value == null)
{
result = default(int);
return false;
}
if (TryParseInt(Value.Trim(), out result))
{
return true;
}
return false;
}
public double AsDouble { get { return ToDouble(); } }
public double ToDouble(double valueIfInvalid = 0)
{
double res;
if (TryConvertDouble(out res))
{
return res;
}
return valueIfInvalid;
}
public bool TryConvertDouble(out double result)
{
if (Value == null)
{
result = default(double);
return false; ;
}
if (TryParseDouble(Value.Trim(), out result))
{
return true;
}
return false;
}
public string AsString { get { return GetString(); } }
public string GetString()
{
return GetString(true, false);
}
public string GetString(bool preserveWhitespace)
{
return GetString(true, preserveWhitespace);
}
public string GetString(bool allowOuterQuotes, bool preserveWhitespace)
{
if (Value == null)
{
return "";
}
var trimmed = Value.Trim();
if (allowOuterQuotes && trimmed.Length >= 2 && trimmed[0] == '"' && trimmed[trimmed.Length - 1] == '"')
{
var inner = trimmed.Substring(1, trimmed.Length - 2);
return preserveWhitespace ? inner : inner.Trim();
}
else
{
return preserveWhitespace ? Value : Value.Trim();
}
}
public override string ToString()
{
return Value;
}
public static implicit operator IniValue(byte o)
{
return new IniValue(o);
}
public static implicit operator IniValue(short o)
{
return new IniValue(o);
}
public static implicit operator IniValue(int o)
{
return new IniValue(o);
}
public static implicit operator IniValue(sbyte o)
{
return new IniValue(o);
}
public static implicit operator IniValue(ushort o)
{
return new IniValue(o);
}
public static implicit operator IniValue(uint o)
{
return new IniValue(o);
}
public static implicit operator IniValue(float o)
{
return new IniValue(o);
}
public static implicit operator IniValue(double o)
{
return new IniValue(o);
}
public static implicit operator IniValue(bool o)
{
return new IniValue(o);
}
public static implicit operator IniValue(string o)
{
return new IniValue(o);
}
private static readonly IniValue _default = new IniValue();
public static IniValue Default { get { return _default; } }
}
public class IniFile : IEnumerable<KeyValuePair<string, IniSection>>, IDictionary<string, IniSection>
{
private Dictionary<string, IniSection> sections;
public IEqualityComparer<string> StringComparer;
public bool SaveEmptySections;
public IniFile()
: this(DefaultComparer)
{
}
public IniFile(IEqualityComparer<string> stringComparer)
{
StringComparer = stringComparer;
sections = new Dictionary<string, IniSection>(StringComparer);
}
public void Save(string path, FileMode mode = FileMode.Create)
{
using (var stream = new FileStream(path, mode, FileAccess.Write))
{
Save(stream);
}
}
public void Save(Stream stream)
{
using (var writer = new StreamWriter(stream))
{
Save(writer);
}
}
public void Save(StreamWriter writer)
{
foreach (var section in sections)
{
if (section.Value.Count > 0 || SaveEmptySections)
{
if (!string.IsNullOrEmpty(section.Value.Comment))
writer.WriteLine(section.Value.Comment);
writer.WriteLine(string.Format("[{0}]", section.Key.Trim()));
foreach (var kvp in section.Value)
{
if (!string.IsNullOrEmpty(kvp.Value.Comment))
writer.WriteLine(kvp.Value.Comment);
writer.WriteLine(string.Format("{0}={1}", kvp.Key, kvp.Value));
}
writer.WriteLine("");
}
}
}
public void Load(string path, bool ordered = false)
{
try
{
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
Load(stream, ordered);
}
}
catch(FileNotFoundException e)
{
}
catch (Exception)
{
throw;
}
}
public void Load(Stream stream, bool ordered = false)
{
using (var reader = new StreamReader(stream, true))
{
Load(reader, ordered);
}
}
public void Load(StreamReader reader, bool ordered = false)
{
IniSection section = null;
string comment = null;
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (line != null)
{
var trimStart = line.TrimStart();
if (trimStart.Length > 0)
{
if (trimStart[0] == ';')
{
if (!string.IsNullOrEmpty(comment))
comment = comment + "\n" + trimStart;
else
comment = trimStart;
}
if (trimStart[0] == '[')
{
var sectionEnd = trimStart.IndexOf(']');
if (sectionEnd > 0)
{
var sectionName = trimStart.Substring(1, sectionEnd - 1).Trim();
section = new IniSection(StringComparer) { Ordered = ordered };
sections[sectionName] = section;
if (comment != null)
{
section.Comment = comment;
comment = null;
}
}
}
else if (section != null && trimStart[0] != ';')
{
string key;
IniValue val;
if (LoadValue(line, out key, out val))
{
if (comment != null)
{
val.Comment = comment;
comment = null;
}
section[key] = val;
}
}
}
}
}
}
private bool LoadValue(string line, out string key, out IniValue val)
{
var assignIndex = line.IndexOf('=');
if (assignIndex <= 0)
{
key = null;
val = null;
return false;
}
key = line.Substring(0, assignIndex).Trim();
var value = line.Substring(assignIndex + 1);
val = new IniValue(value);
return true;
}
public bool ContainsSection(string section)
{
return sections.ContainsKey(section);
}
public bool TryGetSection(string section, out IniSection result)
{
return sections.TryGetValue(section, out result);
}
bool IDictionary<string, IniSection>.TryGetValue(string key, out IniSection value)
{
return TryGetSection(key, out value);
}
public bool Remove(string section)
{
return sections.Remove(section);
}
public IniSection Add(string section, Dictionary<string, IniValue> values, bool ordered = false)
{
return Add(section, new IniSection(values, StringComparer) { Ordered = ordered });
}
public IniSection Add(string section, IniSection value)
{
if (value.Comparer != StringComparer)
{
value = new IniSection(value, StringComparer);
}
sections.Add(section, value);
return value;
}
public IniSection Add(string section, bool ordered = false)
{
var value = new IniSection(StringComparer) { Ordered = ordered };
sections.Add(section, value);
return value;
}
void IDictionary<string, IniSection>.Add(string key, IniSection value)
{
Add(key, value);
}
bool IDictionary<string, IniSection>.ContainsKey(string key)
{
return ContainsSection(key);
}
public ICollection<string> Keys
{
get { return sections.Keys; }
}
public ICollection<IniSection> Values
{
get { return sections.Values; }
}
void ICollection<KeyValuePair<string, IniSection>>.Add(KeyValuePair<string, IniSection> item)
{
((IDictionary<string, IniSection>)sections).Add(item);
}
public void Clear()
{
sections.Clear();
}
bool ICollection<KeyValuePair<string, IniSection>>.Contains(KeyValuePair<string, IniSection> item)
{
return ((IDictionary<string, IniSection>)sections).Contains(item);
}
void ICollection<KeyValuePair<string, IniSection>>.CopyTo(KeyValuePair<string, IniSection>[] array, int arrayIndex)
{
((IDictionary<string, IniSection>)sections).CopyTo(array, arrayIndex);
}
public int Count
{
get { return sections.Count; }
}
bool ICollection<KeyValuePair<string, IniSection>>.IsReadOnly
{
get { return ((IDictionary<string, IniSection>)sections).IsReadOnly; }
}
bool ICollection<KeyValuePair<string, IniSection>>.Remove(KeyValuePair<string, IniSection> item)
{
return ((IDictionary<string, IniSection>)sections).Remove(item);
}
public IEnumerator<KeyValuePair<string, IniSection>> GetEnumerator()
{
return sections.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public IniSection this[string section]
{
get
{
IniSection s;
if (sections.TryGetValue(section, out s))
{
return s;
}
s = new IniSection(StringComparer);
sections[section] = s;
return s;
}
set
{
var v = value;
if (v.Comparer != StringComparer)
{
v = new IniSection(v, StringComparer);
}
sections[section] = v;
}
}
public IniValue Get(string key)
{
var ss = key.Split('.');
if (ss.Length == 2)
{
return this[ss[0]][ss[1]];
}
else
{
return null;
}
}
public void Set(string key, IniValue value)
{
var ss = key.Split('.');
if (ss.Length == 2)
{
var oldValue = this[ss[0]][ss[1]];
if (!string.IsNullOrEmpty(oldValue.AsString))
{
oldValue.Value = value.Value;
this[ss[0]][ss[1]] = oldValue;
}
else
this[ss[0]][ss[1]] = value;
}
}
public string GetContents()
{
using (var stream = new MemoryStream())
{
Save(stream);
stream.Flush();
var builder = new StringBuilder(Encoding.UTF8.GetString(stream.ToArray()));
return builder.ToString();
}
}
public static IEqualityComparer<string> DefaultComparer = new CaseInsensitiveStringComparer();
class CaseInsensitiveStringComparer : IEqualityComparer<string>
{
public bool Equals(string x, string y)
{
return String.Compare(x, y, true) == 0;
}
public int GetHashCode(string obj)
{
return obj.ToLowerInvariant().GetHashCode();
}
#if JS
public new bool Equals(object x, object y) {
var xs = x as string;
var ys = y as string;
if (xs == null || ys == null) {
return xs == null && ys == null;
}
return Equals(xs, ys);
}
public int GetHashCode(object obj) {
if (obj is string) {
return GetHashCode((string)obj);
}
return obj.ToStringInvariant().ToLowerInvariant().GetHashCode();
}
#endif
}
}
public class IniSection : IEnumerable<KeyValuePair<string, IniValue>>, IDictionary<string, IniValue>
{
private Dictionary<string, IniValue> values;
public string Comment;
#region Ordered
private List<string> orderedKeys;
public int IndexOf(string key)
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call IndexOf(string) on IniSection: section was not ordered.");
}
return IndexOf(key, 0, orderedKeys.Count);
}
public int IndexOf(string key, int index)
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call IndexOf(string, int) on IniSection: section was not ordered.");
}
return IndexOf(key, index, orderedKeys.Count - index);
}
public int IndexOf(string key, int index, int count)
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call IndexOf(string, int, int) on IniSection: section was not ordered.");
}
if (index < 0 || index > orderedKeys.Count)
{
throw new IndexOutOfRangeException("Index must be within the bounds." + Environment.NewLine + "Parameter name: index");
}
if (count < 0)
{
throw new IndexOutOfRangeException("Count cannot be less than zero." + Environment.NewLine + "Parameter name: count");
}
if (index + count > orderedKeys.Count)
{
throw new ArgumentException("Index and count were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.");
}
var end = index + count;
for (int i = index; i < end; i++)
{
if (Comparer.Equals(orderedKeys[i], key))
{
return i;
}
}
return -1;
}
public int LastIndexOf(string key)
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call LastIndexOf(string) on IniSection: section was not ordered.");
}
return LastIndexOf(key, 0, orderedKeys.Count);
}
public int LastIndexOf(string key, int index)
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call LastIndexOf(string, int) on IniSection: section was not ordered.");
}
return LastIndexOf(key, index, orderedKeys.Count - index);
}
public int LastIndexOf(string key, int index, int count)
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call LastIndexOf(string, int, int) on IniSection: section was not ordered.");
}
if (index < 0 || index > orderedKeys.Count)
{
throw new IndexOutOfRangeException("Index must be within the bounds." + Environment.NewLine + "Parameter name: index");
}
if (count < 0)
{
throw new IndexOutOfRangeException("Count cannot be less than zero." + Environment.NewLine + "Parameter name: count");
}
if (index + count > orderedKeys.Count)
{
throw new ArgumentException("Index and count were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.");
}
var end = index + count;
for (int i = end - 1; i >= index; i--)
{
if (Comparer.Equals(orderedKeys[i], key))
{
return i;
}
}
return -1;
}
public void Insert(int index, string key, IniValue value)
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call Insert(int, string, IniValue) on IniSection: section was not ordered.");
}
if (index < 0 || index > orderedKeys.Count)
{
throw new IndexOutOfRangeException("Index must be within the bounds." + Environment.NewLine + "Parameter name: index");
}
values.Add(key, value);
orderedKeys.Insert(index, key);
}
public void InsertRange(int index, IEnumerable<KeyValuePair<string, IniValue>> collection)
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call InsertRange(int, IEnumerable<KeyValuePair<string, IniValue>>) on IniSection: section was not ordered.");
}
if (collection == null)
{
throw new ArgumentNullException("Value cannot be null." + Environment.NewLine + "Parameter name: collection");
}
if (index < 0 || index > orderedKeys.Count)
{
throw new IndexOutOfRangeException("Index must be within the bounds." + Environment.NewLine + "Parameter name: index");
}
foreach (var kvp in collection)
{
Insert(index, kvp.Key, kvp.Value);
index++;
}
}
public void RemoveAt(int index)
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call RemoveAt(int) on IniSection: section was not ordered.");
}
if (index < 0 || index > orderedKeys.Count)
{
throw new IndexOutOfRangeException("Index must be within the bounds." + Environment.NewLine + "Parameter name: index");
}
var key = orderedKeys[index];
orderedKeys.RemoveAt(index);
values.Remove(key);
}
public void RemoveRange(int index, int count)
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call RemoveRange(int, int) on IniSection: section was not ordered.");
}
if (index < 0 || index > orderedKeys.Count)
{
throw new IndexOutOfRangeException("Index must be within the bounds." + Environment.NewLine + "Parameter name: index");
}
if (count < 0)
{
throw new IndexOutOfRangeException("Count cannot be less than zero." + Environment.NewLine + "Parameter name: count");
}
if (index + count > orderedKeys.Count)
{
throw new ArgumentException("Index and count were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.");
}
for (int i = 0; i < count; i++)
{
RemoveAt(index);
}
}
public void Reverse()
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call Reverse() on IniSection: section was not ordered.");
}
orderedKeys.Reverse();
}
public void Reverse(int index, int count)
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call Reverse(int, int) on IniSection: section was not ordered.");
}
if (index < 0 || index > orderedKeys.Count)
{
throw new IndexOutOfRangeException("Index must be within the bounds." + Environment.NewLine + "Parameter name: index");
}
if (count < 0)
{
throw new IndexOutOfRangeException("Count cannot be less than zero." + Environment.NewLine + "Parameter name: count");
}
if (index + count > orderedKeys.Count)
{
throw new ArgumentException("Index and count were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.");
}
orderedKeys.Reverse(index, count);
}
public ICollection<IniValue> GetOrderedValues()
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot call GetOrderedValues() on IniSection: section was not ordered.");
}
var list = new List<IniValue>();
for (int i = 0; i < orderedKeys.Count; i++)
{
list.Add(values[orderedKeys[i]]);
}
return list;
}
public IniValue this[int index]
{
get
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot index IniSection using integer key: section was not ordered.");
}
if (index < 0 || index >= orderedKeys.Count)
{
throw new IndexOutOfRangeException("Index must be within the bounds." + Environment.NewLine + "Parameter name: index");
}
return values[orderedKeys[index]];
}
set
{
if (!Ordered)
{
throw new InvalidOperationException("Cannot index IniSection using integer key: section was not ordered.");
}
if (index < 0 || index >= orderedKeys.Count)
{
throw new IndexOutOfRangeException("Index must be within the bounds." + Environment.NewLine + "Parameter name: index");
}
var key = orderedKeys[index];
values[key] = value;
}
}
public bool Ordered
{
get
{
return orderedKeys != null;
}
set
{
if (Ordered != value)
{
orderedKeys = value ? new List<string>(values.Keys) : null;
}
}
}
#endregion
public IniSection()
: this(IniFile.DefaultComparer)
{
}
public IniSection(IEqualityComparer<string> stringComparer)
{
this.values = new Dictionary<string, IniValue>(stringComparer);
}
public IniSection(Dictionary<string, IniValue> values)
: this(values, IniFile.DefaultComparer)
{
}
public IniSection(Dictionary<string, IniValue> values, IEqualityComparer<string> stringComparer)
{
this.values = new Dictionary<string, IniValue>(values, stringComparer);
}
public IniSection(IniSection values)
: this(values, IniFile.DefaultComparer)
{
}
public IniSection(IniSection values, IEqualityComparer<string> stringComparer)
{
this.values = new Dictionary<string, IniValue>(values.values, stringComparer);
}
public void Add(string key, IniValue value)
{
values.Add(key, value);
if (Ordered)
{
orderedKeys.Add(key);
}
}
public bool ContainsKey(string key)
{
return values.ContainsKey(key);
}
/// <summary>
/// Returns this IniSection's collection of keys. If the IniSection is ordered, the keys will be returned in order.
/// </summary>
public ICollection<string> Keys
{
get { return Ordered ? (ICollection<string>)orderedKeys : values.Keys; }
}
public bool Remove(string key)
{
var ret = values.Remove(key);
if (Ordered && ret)
{
for (int i = 0; i < orderedKeys.Count; i++)
{
if (Comparer.Equals(orderedKeys[i], key))
{
orderedKeys.RemoveAt(i);
break;
}
}
}
return ret;
}
public bool TryGetValue(string key, out IniValue value)
{
return values.TryGetValue(key, out value);
}
/// <summary>
/// Returns the values in this IniSection. These values are always out of order. To get ordered values from an IniSection call GetOrderedValues instead.
/// </summary>
public ICollection<IniValue> Values
{
get
{
return values.Values;
}
}
void ICollection<KeyValuePair<string, IniValue>>.Add(KeyValuePair<string, IniValue> item)
{
((IDictionary<string, IniValue>)values).Add(item);
if (Ordered)
{
orderedKeys.Add(item.Key);
}
}
public void Clear()
{
values.Clear();
if (Ordered)
{
orderedKeys.Clear();
}
}
bool ICollection<KeyValuePair<string, IniValue>>.Contains(KeyValuePair<string, IniValue> item)
{
return ((IDictionary<string, IniValue>)values).Contains(item);
}
void ICollection<KeyValuePair<string, IniValue>>.CopyTo(KeyValuePair<string, IniValue>[] array, int arrayIndex)
{
((IDictionary<string, IniValue>)values).CopyTo(array, arrayIndex);
}
public int Count
{
get { return values.Count; }
}
bool ICollection<KeyValuePair<string, IniValue>>.IsReadOnly
{
get { return ((IDictionary<string, IniValue>)values).IsReadOnly; }
}
bool ICollection<KeyValuePair<string, IniValue>>.Remove(KeyValuePair<string, IniValue> item)
{
var ret = ((IDictionary<string, IniValue>)values).Remove(item);
if (Ordered && ret)
{
for (int i = 0; i < orderedKeys.Count; i++)
{
if (Comparer.Equals(orderedKeys[i], item.Key))
{
orderedKeys.RemoveAt(i);
break;
}
}
}
return ret;