class Settings
{
public string Macros_Directory { get; set; }
public string SteamID { get; set; }
public string AccPath { get; set; }
public Settings()
{
string stId = "";
string macDirectory = "";
string account_path = "";
try
{
StreamReader sr = new StreamReader("**");
stId = sr.ReadToEnd().Trim();
sr.Close();
}
catch (Exception) { }
try
{
StreamReader sr = new StreamReader("**");
macDirectory = sr.ReadToEnd().Trim();
sr.Close();
}
catch (Exception) { }
try
{
StreamReader sr = new StreamReader("**");
account_path = sr.ReadToEnd().Trim();
sr.Close();
}
catch (Exception) { }
if (macDirectory.Trim() != "" && stId.Trim() != "" && account_path.Trim() != "")
{
Macros_Directory = macDirectory;
SteamID = stId;
AccPath = account_path;
}
else
{
Macros_Directory = "";
SteamID = "";
AccPath = "";
}
}
public void Save(string macDir, string steamid, string accpath)
{
StreamWriter stid = new StreamWriter("**");
stid.WriteLine(steamid);
stid.Close();
StreamWriter macD = new StreamWriter("**");
macD.WriteLine(macDir);
macD.Close();
StreamWriter accPath = new StreamWriter("**");
accPath.WriteLine(accpath);
accPath.Close();
Macros_Directory = macDir;
SteamID = steamid;
AccPath = accpath;
}
public void Save(string accpath)
{
StreamWriter accPath = new StreamWriter("**");
accPath.WriteLine(accpath);
accPath.Close();
AccPath = accpath;
}
public void Save(string macDir) // Тип "Settings" уже определяет член "Save" с такими же типами параметрами
{ // ERROR
StreamWriter macD = new StreamWriter("**");
macD.WriteLine(macDir);
macD.Close();
Macros_Directory = macDir;
}
}
public void Save(string accpath, string macDir = null, string stId = null)
{
try
{
using(var sw = new StreamWriter("**"))
{
if(!string.IsNullOrEmpty(accpath))
{
sw.WriteLine(accpath);
AccPath = accpath
}
if(!string.IsNullOrEmpty(macDir))
{
sw.WriteLine(macDir);
Macros_Directory = macDir;
}
if(!string.IsNullOrEmpty(stId))
{
sw.WriteLine = stId;
SteamID = stId;
}
}
}
catch(Exception ex) { }
}
Save(accpath)
Save(accpath, macDir)
Save(accpath, macDir, stId)
Save(null, macDir, stId)
Save(accpath, null, stId)
public interface IStreamSourceWriter: IDisposable {
WriteLine(string);
}
public void SaveFromSource(IStreamSourceWriter streamSourceWriter) {
// код ниже уходит в реализацию паттерна интерфейс, то есть в IStreamSourceWriter)
// управление временем жизни уходит в реализацию паттерна
// using(StreamWriter stid = new StreamWriter("**");
// stid.WriteLine(steamid);
// stid.Close();
streamSourceWriter.WriteLine(steamid);
}
public void SaveFromSources(IEnumerable<IStreamSourceWriter> streamSourceWriters) {
foreach(source in streamSourceWriters) {
SaveFromSource(source);
}
}