タイトルからわかるように、Settings.cs ファイルを変更しました。いくつかのプロパティ、いくつかのコードをコンストラクター (public Settings()) に追加し、Save() 関数をオーバーライドしました。 IDE で生成されたファイル、特に .designers を変更するときに直面する問題です。これはデザイナーではなく、IDE で生成された内部のシールされたパーシャルであり、100% 安全かどうかを知りたいですか?
internal sealed partial class Settings
{
public System.Data.SqlClient.SqlConnection AppDbConnection
{
get
{
if (_AppDbConnection == null)
{
try
{
_AppDbConnection = new System.Data.SqlClient.SqlConnection(_ConnectionString);
_AppDbConnection.Open();
}
catch (System.Exception ex) { throw ex; }
}
return _AppDbConnection;
}
}
private System.Data.SqlClient.SqlConnection _AppDbConnection;
private string _ConnectionString;
public override void Save()
{
System.IO.FileInfo fi = new System.IO.FileInfo(System.Windows.Forms.Application.StartupPath + "\\Settings.dat");
System.IO.FileStream fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
System.IO.StreamWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.GetEncoding("iso-8859-9"));
try { sw.Write(Helper.BinarySerializer.ToBinary(_SettingsBase)); }
catch (System.Exception ex) { throw ex; }
finally { sw.Close(); fs.Close(); }
base.Save();
}
public Settings()
{
try
{
System.IO.FileInfo fi = new System.IO.FileInfo(System.Windows.Forms.Application.StartupPath + "\\Settings.dat");
if (fi.Exists)
{
System.IO.FileStream fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.StreamReader sr = new System.IO.StreamReader(fs, System.Text.Encoding.GetEncoding("iso-8859-9"));
string data = sr.ReadToEnd();
if (data != "")
{
_SettingsBase = (AppCode.SettingsBase)Helper.BinarySerializer.BinaryTo(data);
_ConnectionString = Helper.Crypto.DecryptString(_SettingsBase.ConnectionString, "");
}