正如您从标题中可以理解的那样,我修改了 Settings.cs 文件。添加了一些属性,一些代码到构造函数(公共 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, "");
}