-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
partially fixes #17 - Hard to parse redis config file due to non sect…
…ion and space separated kv
- Loading branch information
Showing
17 changed files
with
360 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Salaros.Configuration | ||
{ | ||
public partial class ConfigParser | ||
{ | ||
public class NullConfigSection | ||
{ | ||
private ConfigParser parent; | ||
|
||
public NullConfigSection(ConfigParser parent) | ||
{ | ||
this.parent = parent; | ||
} | ||
|
||
public T GetValue<T>(string keyName, T defaultValue = default(T)) | ||
{ | ||
if (string.IsNullOrWhiteSpace(keyName)) | ||
throw new ArgumentException("Key name must be a non-empty string.", nameof(keyName)); | ||
|
||
var iniKey = new ConfigKeyValue<T>(keyName, parent.Settings.KeyValueSeparator, defaultValue, -1); | ||
var key = parent.fileHeader.Section.Keys.FirstOrDefault(k => Equals(keyName, k.Name)); | ||
if (key != null) | ||
return (T)key.ValueRaw; | ||
|
||
parent.fileHeader.Section.AddLine(iniKey); | ||
return defaultValue; | ||
} | ||
|
||
public string GetValue(string keyName, string defaultValue = null) => GetValue<string>(keyName, defaultValue); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.