35 lines
766 B
C#
35 lines
766 B
C#
namespace RanazePos.Api.Infrastructure;
|
|
|
|
public static class DotEnvLoader
|
|
{
|
|
public static IDictionary<string, string?> Load(string path)
|
|
{
|
|
var values = new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
|
|
if (!File.Exists(path))
|
|
{
|
|
return values;
|
|
}
|
|
|
|
foreach (var rawLine in File.ReadAllLines(path))
|
|
{
|
|
var line = rawLine.Trim();
|
|
if (string.IsNullOrWhiteSpace(line) || line.StartsWith('#'))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var separatorIndex = line.IndexOf('=');
|
|
if (separatorIndex <= 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var key = line[..separatorIndex].Trim();
|
|
var value = line[(separatorIndex + 1)..].Trim().Trim('"');
|
|
values[key] = value;
|
|
}
|
|
|
|
return values;
|
|
}
|
|
}
|