.
.NET 설정 항목만큼 쉽지 않을 수도 있습니다. 나는 어쨌든 그들을 사용하지 못했습니다.
예를 들어, 아래 클래스가 있습니다. 내가 필요로하는 것은 그것이 가져 오거나 속성을 설정해야 할 일, 그들은 자동/저장로드하고 있습니다 :
using Nini.Config;
public class DbConfig : PropertyNotifierBase {
private static readonly string PROGRAM_NAME = "programname";
private static readonly string CONFIG_NAME = "Database";
private static DbConfig _instance = new DbConfig();
public static DbConfig Instance { get { return (_instance); } }
private DbConfig() {
SetupPaths();
Source = new XmlConfigSource(FullConfigFilename);
Source.AutoSave = true;
CreateSectionsIfNeeded();
}
private void CreateSectionsIfNeeded() {
if (Source.Configs["Database"] == null)
Source.AddConfig("Database");
}
private void SetupPaths() {
ConfigPath = DetermineConfigPath();
ConfigFilename = String.Format("{0}.xml", CONFIG_NAME);
Directory.CreateDirectory(ConfigPath);
// Create an empty configuration file if it isn't there.
if (!File.Exists(FullConfigFilename))
File.WriteAllText(FullConfigFilename, "<Nini>\n</Nini>\n");
}
private IConfigSource Source { get; set; }
public String ConfigPath { get; private set; }
public String ConfigFilename { get; private set; }
public String FullConfigFilename { get { return (Path.Combine(ConfigPath, ConfigFilename)); } }
public String SqlServerInstance {
get { return (Source.Configs["Database"].GetString("SqlServerInstance", @"somedefaultconnection")); }
set { Source.Configs["Database"].Set("SqlServerInstance", value); NotifyPropertyChanged("SqlServerInstance"); }
}
public String SqlServerDatabase {
get { return (Source.Configs["Database"].GetString("SqlServerDatabase", "somedatabasename")); }
set { Source.Configs["Database"].Set("SqlServerDatabase", value); NotifyPropertyChanged("SqlServerDatabase"); }
}
public String SqlServerUsername {
get { return (Source.Configs["Database"].GetString("SqlServerUsername", "someusername")); }
set { Source.Configs["Database"].Set("SqlServerUsername", value); NotifyPropertyChanged("SqlServerUsername"); }
}
public String SqlServerPassword {
get { return (Source.Configs["Database"].GetString("SqlServerPassword", "somepassword")); }
set { Source.Configs["Database"].Set("SqlServerPassword", value); NotifyPropertyChanged("SqlServerPassword"); }
}
private string DetermineConfigPath() {
String filename = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
filename += Path.DirectorySeparatorChar + PROGRAM_NAME;
return (filename);
}
}
당신은 사용자 편집이 Properties.Settings.Default''가 아닌 다른 하나가 될 수있는 개체가 수 있으며, 'Save()'를 호출하기 전에 객체에서 저장하고자하는 설정 만 그 객체로 옮기십시오. – millimoose