Skip to content

Commit

Permalink
Fixed bool toggles in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
NostraThomas99 committed Apr 7, 2024
1 parent e29b64a commit 40a9b39
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions RotationSolver/Commands/RSCommands_OtherCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ private static void DoSettingCommand(string str)
}
var value = strs.LastOrDefault();

foreach (var property in typeof(Configs).GetRuntimeProperties())

foreach (var property in typeof(Configs).GetRuntimeProperties()
.Where(p => p.GetMethod?.IsPublic ?? false))
{
if (!str.StartsWith(property.Name, StringComparison.OrdinalIgnoreCase)) continue;

Expand All @@ -58,11 +60,18 @@ private static void DoSettingCommand(string str)
type = typeof(bool);
}

var v = Convert.ChangeType(value, type);
object v;
try { v = Convert.ChangeType(value, type); }
catch { v = null; }

if (v == null && type == typeof(bool))
{
v = !(bool)property.GetValue(Service.Config)!;
var config = property.GetValue(Service.Config);
if (config is ConditionBoolean relay)
{
relay.Value = !relay.Value;
v = relay.Value;
}
}

if (property.PropertyType == typeof(ConditionBoolean))
Expand Down

0 comments on commit 40a9b39

Please sign in to comment.