Skip to content

Commit

Permalink
fix: benutzereingabe string always returned null
Browse files Browse the repository at this point in the history
  • Loading branch information
PocketMiner82 committed Apr 15, 2024
1 parent 23d1bb7 commit 36700b3
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pseudocodeIde/interpreter/csharpcode/TemplateCodeOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,22 @@ protected virtual void _warte(int millis)

try
{
return prompt.ShowDialog() == DialogResult.OK && double.TryParse(textBox.Text, out double result)
? (T?)Convert.ChangeType(result, Nullable.GetUnderlyingType(typeof(T)))
: (T?)Convert.ChangeType(textBox.Text, Nullable.GetUnderlyingType(typeof(T)));
}
catch
{
return default;
DialogResult result = prompt.ShowDialog();
Type nullableType = Nullable.GetUnderlyingType(typeof(T));
Type type = typeof(T);
Type usedType = nullableType ?? type;

if (result == DialogResult.OK)
{
return (usedType == typeof(double) || usedType == typeof(int))
&& double.TryParse(textBox.Text, out double parsed)
? (T)Convert.ChangeType(parsed, usedType)
: (T)Convert.ChangeType(textBox.Text, usedType);
}
}
catch { }

return default;
}
}

Expand Down

0 comments on commit 36700b3

Please sign in to comment.