Files
Toolkit2/Toolkit.Foundation/ConfigurationValue.cs
T
TheXamlGuy bc55c4649b tidy
2024-04-26 23:05:36 +01:00

25 lines
631 B
C#

namespace Toolkit.Foundation;
public class ConfigurationValue<TConfiguration, TValue>(Func<TConfiguration, Action<TValue>> changed)
where TValue :
class, new()
{
private TValue? currentValue;
public bool TryUpdate(TConfiguration configuration,
out TValue value)
{
TValue newValue = new();
changed(configuration).Invoke(newValue);
if (!EqualityComparer<TValue>.Default.Equals(currentValue, newValue))
{
value = newValue;
currentValue = newValue;
return true;
}
value = currentValue!;
return false;
}
}