summaryrefslogtreecommitdiff
path: root/src/TrainerMod/Framework/Extensions.cs
blob: da3a2f03ba897360b851e4e63ba2491d27e25771 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
namespace TrainerMod.Framework
{
    /// <summary>Provides extension methods on primitive types.</summary>
    internal static class Extensions
    {
        /*********
        ** Public methods
        *********/
        /// <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());
        }
    }
}