NewLife/X

[fix]Config创建默认配置文件的开关Runtime.CreateConfigOnMissing,仅需对自动创建生效,而不应该阻止用户主动Save
智能大石头 authored at 2024-08-09 00:30:41 石头 committed at 2024-08-10 14:22:24
1d251e0
Tree
1 Parent(s) a53cc01
Summary: 1 changed files with 2 additions and 10 deletions.
Modified +2 -10
Modified +2 -10
diff --git a/NewLife.Core/Configuration/Config.cs b/NewLife.Core/Configuration/Config.cs
index 711299d..1e2c11c 100644
--- a/NewLife.Core/Configuration/Config.cs
+++ b/NewLife.Core/Configuration/Config.cs
@@ -86,7 +86,7 @@ public class Config<TConfig> where TConfig : Config<TConfig>, new()
                 {
                     // OnLoad 中可能有变化,存回去
                     //prv.Save(config);
-                    config.Save();
+                    if (!prv.IsNew || Runtime.CreateConfigOnMissing) config.Save();
                 }
                 catch (Exception ex)
                 {
@@ -113,14 +113,6 @@ public class Config<TConfig> where TConfig : Config<TConfig>, new()
 
     /// <summary>保存到配置文件中去</summary>
     //[Obsolete("=>Provider.Save")]
-    public virtual void Save()
-    {
-        var prv = Provider;
-        if (prv == null) return;
-
-        // 是否创建默认配置
-        if (!prv.IsNew || Runtime.CreateConfigOnMissing)
-            prv.Save(this);
-    }
+    public virtual void Save() => Provider?.Save(this);
     #endregion
 }
\ No newline at end of file