diff options
Diffstat (limited to 'src/TrainerMod/Framework/Extensions.cs')
-rw-r--r-- | src/TrainerMod/Framework/Extensions.cs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/TrainerMod/Framework/Extensions.cs b/src/TrainerMod/Framework/Extensions.cs new file mode 100644 index 00000000..30019748 --- /dev/null +++ b/src/TrainerMod/Framework/Extensions.cs @@ -0,0 +1,22 @@ +namespace TrainerMod.Framework +{ + /// <summary>Provides extension methods on primitive types.</summary> + public static class Extensions + { + /// <summary>Get whether an object is a number.</summary> + /// <param name="value">The object value.</param> + public static bool IsInt(this object value) + { + int i; + return int.TryParse(value.ToString(), out i); + } + + /// <summary>Parse an object into a number.</summary> + /// <param name="value">The object value.</param> + /// <exception cref="System.FormatException">The value is not a valid number.</exception> + public static int ToInt(this object value) + { + return int.Parse(value.ToString()); + } + } +} |