Use CallerMemberName Attribute so you do not have any magic strings in settings.cs (#73)
Use CallerMemberName Attribute so you do not have any magic strings in settings.cs (#73)
diff --git a/PokemonGo/RocketAPI/Console/Settings.cs b/PokemonGo/RocketAPI/Console/Settings.cs
index e85349f..0283133 100644
--- a/PokemonGo/RocketAPI/Console/Settings.cs
+++ b/PokemonGo/RocketAPI/Console/Settings.cs
@@ -2,30 +2,31 @@
using PokemonGo.RocketAPI.Enums;
using PokemonGo.RocketAPI.GeneratedCode;
using System;
+using System.Runtime.CompilerServices;
namespace PokemonGo.RocketAPI.Console
{
public class Settings : ISettings
{
- public AuthType AuthType => (AuthType)Enum.Parse(typeof(AuthType), GetSetting("AuthType"));
- public string PtcUsername => GetSetting("PtcUsername") != string.Empty ? GetSetting("PtcUsername") : "username";
- public string PtcPassword => GetSetting("PtcPassword") != string.Empty? GetSetting("PtcPassword") : "password";
- public double DefaultLatitude => GetSetting("DefaultLatitude") != string.Empty ? double.Parse(GetSetting("DefaultLatitude")) : 52.379189; //Default Amsterdam Central Station
- public double DefaultLongitude => GetSetting("DefaultLongitude") != string.Empty ? double.Parse(GetSetting("DefaultLongitude")) : 4.899431;//Default Amsterdam Central Station
+ public AuthType AuthType => (AuthType)Enum.Parse(typeof(AuthType), GetSetting());
+ public string PtcUsername => GetSetting() != string.Empty ? GetSetting() : "username";
+ public string PtcPassword => GetSetting() != string.Empty? GetSetting() : "password";
+ public double DefaultLatitude => GetSetting() != string.Empty ? double.Parse(GetSetting()) : 52.379189; //Default Amsterdam Central Station
+ public double DefaultLongitude => GetSetting() != string.Empty ? double.Parse(GetSetting()) : 4.899431;//Default Amsterdam Central Station
public string GoogleRefreshToken
{
- get { return GetSetting("GoogleRefreshToken") != string.Empty ? GetSetting("GoogleRefreshToken") : string.Empty; }
- set { SetSetting("GoogleRefreshToken", value); }
+ get { return GetSetting() != string.Empty ? GetSetting() : string.Empty; }
+ set { SetSetting(value); }
}
- private string GetSetting(string key)
+ private string GetSetting([CallerMemberName]string key = null)
{
return ConfigurationManager.AppSettings[key];
}
- private void SetSetting(string key, string value)
+ private void SetSetting(string value, [CallerMemberName]string key = null)
{
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- configFile.AppSettings.Settings[key].Value = value;
+ if (key != null) configFile.AppSettings.Settings[key].Value = value;
configFile.Save();
}
}
You may download the files in Public Git.