SystemTrayMenu/Helper/File/FileIni.cs

27 lines
797 B
C#
Raw Normal View History

using System.Collections.Generic;
2019-07-05 05:04:14 +12:00
using System.IO;
using System.Linq;
namespace SystemTrayMenu.Helper
{
public class FileIni
{
private readonly Dictionary<string, string> values;
2019-07-05 05:04:14 +12:00
public FileIni(string path)
{
values = File.ReadLines(path)
.Where(line => (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#")))
2019-07-05 05:04:14 +12:00
.Select(line => line.Split(new char[] { '=' }, 2, 0))
.ToDictionary(parts => parts[0].Trim(), parts => parts.Length > 1 ? parts[1].Trim() : null);
}
public string Value(string name, string value = null)
{
if (values != null && values.ContainsKey(name))
{
return values[name];
}
return value;
}
}
}