我向项目中添加了应用程序设置。这些设置保存在 'NameOfMyApp.exe.config' 中。如果有人删除了这个文件,会发生什么?是否需要重新创建它?在哪里存储默认设置的值?
using System;
using System.Windows.Forms;
namespace AppSettings {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
textBox1.Text = Properties.Settings.Default.tbText;
}
}
}
TbText的范围是应用程序。我以发布模式编译它。我删除了除*.exe之外的所有文件。这是有效的,因为这个设置在程序集中:
namespace AppSettings.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
//here!
[global::System.Configuration.DefaultSettingValueAttribute("!!!***HALLO***!!!")]
//
public string tbText {
get {
return ((string)(this["tbText"]));
}
}
}
}