Improve LaunchSettings constructor (#4889)

* update log ident

* move flagMap inside the ctor function
This commit is contained in:
Matt 2025-03-15 17:53:00 +00:00 committed by GitHub
parent d244f42b49
commit afc3200b68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -57,11 +57,9 @@ namespace Bloxstrap
/// </summary>
public string[] Args { get; private set; }
private readonly Dictionary<string, LaunchFlag> _flagMap = new();
public LaunchSettings(string[] args)
{
const string LOG_IDENT = "LaunchSettings";
const string LOG_IDENT = "LaunchSettings::LaunchSettings";
#if DEBUG
App.Logger.WriteLine(LOG_IDENT, $"Launched with arguments: {string.Join(' ', args)}");
@ -69,6 +67,8 @@ namespace Bloxstrap
Args = args;
Dictionary<string, LaunchFlag> flagMap = new();
// build flag map
foreach (var prop in this.GetType().GetProperties())
{
@ -79,7 +79,7 @@ namespace Bloxstrap
continue;
foreach (string identifier in flag.Identifiers.Split(','))
_flagMap.Add(identifier, flag);
flagMap.Add(identifier, flag);
}
int startIdx = 0;
@ -119,7 +119,7 @@ namespace Bloxstrap
string identifier = arg[1..];
if (!_flagMap.TryGetValue(identifier, out LaunchFlag? flag) || flag is null)
if (!flagMap.TryGetValue(identifier, out LaunchFlag? flag) || flag is null)
{
App.Logger.WriteLine(LOG_IDENT, $"Unknown argument: {identifier}");
continue;