Catch bad user input on number input

This commit is contained in:
Sinai 2021-05-08 06:17:30 +10:00
parent d34aeb81b3
commit 3d94b51d40

View File

@ -100,6 +100,8 @@ namespace UnityExplorer.UI.CacheObject
value = value.TryCast(FallbackType); value = value.TryCast(FallbackType);
TrySetUserValue(value); TrySetUserValue(value);
SetDataToCell(CellView);
} }
public abstract void TrySetUserValue(object value); public abstract void TrySetUserValue(object value);
@ -345,16 +347,27 @@ namespace UnityExplorer.UI.CacheObject
SetUserValue(this.CellView.Toggle.isOn); SetUserValue(this.CellView.Toggle.isOn);
else else
{ {
var type = Value.GetActualType(); try
if (!numberParseMethods.ContainsKey(type.AssemblyQualifiedName))
{ {
var method = type.GetMethod("Parse", new Type[] { typeof(string) }); var type = Value.GetActualType();
numberParseMethods.Add(type.AssemblyQualifiedName, method); if (!numberParseMethods.ContainsKey(type.AssemblyQualifiedName))
} {
var method = type.GetMethod("Parse", new Type[] { typeof(string) });
numberParseMethods.Add(type.AssemblyQualifiedName, method);
}
var val = numberParseMethods[type.AssemblyQualifiedName]
.Invoke(null, new object[] { CellView.InputField.Text });
var val = numberParseMethods[type.AssemblyQualifiedName] SetUserValue(val);
.Invoke(null, new object[] { CellView.InputField.Text }); }
SetUserValue(val); catch (ArgumentException) { } // ignore bad user input
catch (FormatException) { }
catch (OverflowException) { }
catch (Exception ex)
{
ExplorerCore.LogWarning("CacheObjectBase OnCellApplyClicked (number): " + ex.ToString());
}
} }
SetDataToCell(this.CellView); SetDataToCell(this.CellView);
@ -367,6 +380,10 @@ namespace UnityExplorer.UI.CacheObject
if (this.IValue == null) if (this.IValue == null)
{ {
var ivalueType = InteractiveValue.GetIValueTypeForState(State); var ivalueType = InteractiveValue.GetIValueTypeForState(State);
if (ivalueType == null)
return;
IValue = (InteractiveValue)Pool.Borrow(ivalueType); IValue = (InteractiveValue)Pool.Borrow(ivalueType);
CurrentIValueType = ivalueType; CurrentIValueType = ivalueType;
@ -389,18 +406,6 @@ namespace UnityExplorer.UI.CacheObject
CellView.RefreshSubcontentButton(); CellView.RefreshSubcontentButton();
} }
public virtual void SetValueFromIValue(object value)
{
if (CellView == null)
{
ExplorerCore.LogWarning("Trying to set value from IValue but CellView is null!?");
return;
}
SetUserValue(value);
SetDataToCell(CellView);
}
public virtual void ReleaseIValue() public virtual void ReleaseIValue()
{ {
if (IValue == null) if (IValue == null)