R# code improvements

This commit is contained in:
JustArchi
2020-04-18 16:54:57 +02:00
parent df8044ba74
commit 4b4b323164
10 changed files with 60 additions and 97 deletions

View File

@@ -74,9 +74,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
}
if ((ASF.GlobalConfig.AdditionalProperties != null) && (ASF.GlobalConfig.AdditionalProperties.Count > 0)) {
if (request.GlobalConfig.AdditionalProperties == null) {
request.GlobalConfig.AdditionalProperties = new Dictionary<string, JToken>(ASF.GlobalConfig.AdditionalProperties.Count, ASF.GlobalConfig.AdditionalProperties.Comparer);
}
request.GlobalConfig.AdditionalProperties ??= new Dictionary<string, JToken>(ASF.GlobalConfig.AdditionalProperties.Count, ASF.GlobalConfig.AdditionalProperties.Comparer);
foreach ((string key, JToken value) in ASF.GlobalConfig.AdditionalProperties.Where(property => !request.GlobalConfig.AdditionalProperties.ContainsKey(property.Key))) {
request.GlobalConfig.AdditionalProperties.Add(key, value);

View File

@@ -122,9 +122,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
}
if ((bot.BotConfig.AdditionalProperties != null) && (bot.BotConfig.AdditionalProperties.Count > 0)) {
if (request.BotConfig.AdditionalProperties == null) {
request.BotConfig.AdditionalProperties = new Dictionary<string, JToken>(bot.BotConfig.AdditionalProperties.Count, bot.BotConfig.AdditionalProperties.Comparer);
}
request.BotConfig.AdditionalProperties ??= new Dictionary<string, JToken>(bot.BotConfig.AdditionalProperties.Count, bot.BotConfig.AdditionalProperties.Comparer);
foreach ((string key, JToken value) in bot.BotConfig.AdditionalProperties.Where(property => !request.BotConfig.AdditionalProperties.ContainsKey(property.Key))) {
request.BotConfig.AdditionalProperties.Add(key, value);

View File

@@ -69,7 +69,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
}
}
foreach (PropertyInfo property in targetType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(property => property.CanRead && !property.GetMethod.IsPrivate)) {
foreach (PropertyInfo property in targetType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(property => property.CanRead && (property.GetMethod?.IsPrivate == false))) {
JsonPropertyAttribute jsonProperty = property.GetCustomAttribute<JsonPropertyAttribute>();
if (jsonProperty != null) {
@@ -81,7 +81,15 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
underlyingType = enumType.GetUnifiedName();
foreach (object value in Enum.GetValues(targetType)) {
body[value.ToString()] = Convert.ChangeType(value, enumType).ToString();
string valueText = value.ToString();
if (string.IsNullOrEmpty(valueText)) {
ASF.ArchiLogger.LogNullError(nameof(valueText));
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorObjectIsNull, nameof(valueText))));
}
body[valueText] = Convert.ChangeType(value, enumType).ToString();
}
}