Object - IsValidUInt64

An object extension method that query if '@this' is valid ulong.

Try it

public static void Main()
{
	string format = "{0, -40} {1, -15}";
	object [] values = { "-128" , "89","ABC", "true", "12/31/2018", "899", ".", "546565255465", "10888", "5465665", "4/2/2007 7:23:57 PM -07:00"};
	
	Console.WriteLine(format, "Object", "Is Valid UInt64");
	Console.WriteLine(format, "------", "---------------");
	
	foreach(var val in values)
	{
		// C# Extension Method: Object - IsValidUInt64
		Console.WriteLine(format, val, val.IsValidUInt64());
	}
}

View Source
public static partial class Extensions
{
    /// <summary>
    ///     An object extension method that query if '@this' is valid ulong.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <returns>true if valid ulong, false if not.</returns>
    public static bool IsValidUInt64(this object @this)
    {
        if (@this == null)
        {
            return true;
        }

        ulong result;
        return ulong.TryParse(@this.ToString(), out result);
    }
}