Skip to content

Commit

Permalink
重构 Parameters 类,增加对类型转换的支持。 🐮
Browse files Browse the repository at this point in the history
  • Loading branch information
PopeyeZhong committed Apr 1, 2024
1 parent 8c1c17c commit 08d99b6
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Zongsoft.Core/src/Collections/Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,27 @@ public void Clear()
dictionary.Clear();
}

public bool Contains(string name) => _owner.IsAlive && name != null && _cache.TryGetValue(_owner, out var dictionary) && dictionary.ContainsKey(name);
public readonly bool Contains(string name) => _owner.IsAlive && name != null && _cache.TryGetValue(_owner, out var dictionary) && dictionary.ContainsKey(name);
public readonly object GetValue(string name) => _owner.IsAlive && name != null && _cache.TryGetValue(_owner, out var dictionary) && dictionary.TryGetValue(name, out var value) ? value : null;
public readonly T GetValue<T>(string name, T defaultValue) => _owner.IsAlive && name != null && _cache.TryGetValue(_owner, out var dictionary) && dictionary.TryGetValue(name, out var value) ?
Common.Convert.ConvertValue<T>(value) : defaultValue;

public bool TryGetValue(string name, out object value)
public readonly bool TryGetValue(string name, out object value)
{
value = null;
value = default;
return _owner.IsAlive && name != null && _cache.TryGetValue(_owner, out var dictionary) && dictionary.TryGetValue(name, out value);
}

public bool HasValue(string name) => _owner.IsAlive && name != null && _cache.TryGetValue(_owner, out var dictionary) && dictionary.ContainsKey(name);
public bool HasValue(string name, out object value)
public readonly bool TryGetValue<T>(string name, out T value)
{
value = null;
return _owner.IsAlive && name != null && _cache.TryGetValue(_owner, out var dictionary) && dictionary.TryGetValue(name, out value);
if(_owner.IsAlive && name != null && _cache.TryGetValue(_owner, out var dictionary) && dictionary.TryGetValue(name, out var result))
{
value = Common.Convert.ConvertValue<T>(result);
return true;
}

value = default;
return false;
}

public void SetValue(string name, object value)
Expand Down

0 comments on commit 08d99b6

Please sign in to comment.