Skip to content

Commit

Permalink
Always initialize validators
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Jun 10, 2024
1 parent 8acf986 commit d314835
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/ConfigFactory.Core/ConfigModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,11 @@ void IConfigModule.Load(ref IConfigModule module)

public virtual void Load(ref T module)
{
if (!File.Exists(module.LocalPath)) {
module.Save();
return;
if (File.Exists(module.LocalPath)) {
using FileStream fs = File.OpenRead(module.LocalPath);
module = JsonSerializer.Deserialize<T>(fs)!;
}

using FileStream fs = File.OpenRead(module.LocalPath);
module = JsonSerializer.Deserialize<T>(fs)!;

foreach (var (name, (property, _)) in module.Properties) {
typeof(T).GetMethod($"On{name}Changed", BindingFlags.NonPublic | BindingFlags.Instance)?
.Invoke(module, [property.GetValue(module)]);
Expand Down

0 comments on commit d314835

Please sign in to comment.