feat: added default valueless Get to IConfiguration for nullables
This commit is contained in:
@@ -12,17 +12,18 @@ public class BasicConfiguration : IConfiguration
|
||||
|
||||
public IReadOnlyDictionary<string, object?> Values => values;
|
||||
|
||||
public T? Get<T>(string key, T? defaultValue = default)
|
||||
public T Get<T>(string key, T defaultValue) => Get<T>(key) ?? defaultValue;
|
||||
public T? Get<T>(string key)
|
||||
{
|
||||
if (!values.TryGetValue(key, out object? value))
|
||||
return defaultValue;
|
||||
return default;
|
||||
|
||||
if (value is T castedObject)
|
||||
return castedObject;
|
||||
|
||||
try { return (T?)System.Convert.ChangeType(value, typeof(T)); } catch { }
|
||||
|
||||
return defaultValue;
|
||||
return default;
|
||||
}
|
||||
|
||||
public object? Get(string key)
|
||||
|
||||
Reference in New Issue
Block a user