Skip to content

Commit

Permalink
Add reset function to IConfigModule
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Jul 11, 2023
1 parent 42e4dfd commit ffb50ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ConfigFactory.Core/ConfigModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ IConfigModule IConfigModule.Load()
return result;
}

public void Reset()
{
IConfigModule config = Load();
foreach ((var name, (var property, _)) in Properties) {
property.SetValue(Shared, config.Properties[name].Property.GetValue(config));
}
}

protected void SetValidation<TProperty>(Expression<Func<TProperty>> property, Func<TProperty?, bool> validation,
string? invalidErrorMessage = null, string? validationFailureColor = null, string? validationSuccessColor = null)
{
Expand Down
6 changes: 6 additions & 0 deletions src/ConfigFactory.Core/IConfigModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public interface IConfigModule
/// <returns></returns>
public IConfigModule Load();

/// <summary>
/// Resets the <see cref="Properties"/> to their last saved values
/// </summary>
/// <returns></returns>
public void Reset();

/// <summary>
/// Saves the current <see cref="IConfigModule"/> instance
/// </summary>
Expand Down

0 comments on commit ffb50ba

Please sign in to comment.