Created
December 3, 2019 19:15
-
-
Save gavilanch/4c0647820f52491f88638cf843dfbb48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InputSelectNumber<T> : InputSelect<T> | |
{ | |
protected override bool TryParseValueFromString(string value, out T result, out string validationErrorMessage) | |
{ | |
if (typeof(T) == typeof(int)) | |
{ | |
if (int.TryParse(value, out var resultInt)) | |
{ | |
result = (T)(object)resultInt; | |
validationErrorMessage = null; | |
return true; | |
} | |
else | |
{ | |
result = default; | |
validationErrorMessage = "The chosen value is not a valid number."; | |
return false; | |
} | |
} | |
else | |
{ | |
return base.TryParseValueFromString(value, out result, out validationErrorMessage); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment