Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4517/src/Spring/Spring.Core/Util
Modified Files:
NumberUtils.cs
Log Message:
SPRNET-898
Index: NumberUtils.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util/NumberUtils.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** NumberUtils.cs 17 Feb 2007 08:28:12 -0000 1.5
--- NumberUtils.cs 20 Mar 2008 23:58:16 -0000 1.6
***************
*** 22,25 ****
--- 22,27 ----
using System;
+ using System.ComponentModel;
+ using Spring.Core.TypeConversion;
#endregion
***************
*** 61,73 ****
public static bool IsDecimal(object number)
{
return (number is Single || number is Double || number is Decimal);
}
/// <summary>
! /// Determines whether the supplied <paramref name="number"/> is decimal number.
/// </summary>
/// <param name="number">The object to check.</param>
/// <returns>
! /// <c>true</c> if the specified object is decimal number; otherwise, <c>false</c>.
/// </returns>
public static bool IsNumber(object number)
--- 63,76 ----
public static bool IsDecimal(object number)
{
+
return (number is Single || number is Double || number is Decimal);
}
/// <summary>
! /// Determines whether the supplied <paramref name="number"/> is of numeric type.
/// </summary>
/// <param name="number">The object to check.</param>
/// <returns>
! /// <c>true</c> if the specified object is of numeric type; otherwise, <c>false</c>.
/// </returns>
public static bool IsNumber(object number)
***************
*** 76,79 ****
--- 79,130 ----
}
+ /// <summary>
+ /// Determines whether the supplied <paramref name="number"/> can be converted to an integer.
+ /// </summary>
+ /// <param name="number">The object to check.</param>
+ /// <returns>
+ /// <see lang="true"/> if the supplied <paramref name="number"/> can be converted to an integer.
+ /// </returns>
+ public static bool CanConvertToInteger(object number)
+ {
+ TypeConverter converter = TypeDescriptor.GetConverter(number);
+ return (converter.CanConvertTo(typeof(Int32))
+ || converter.CanConvertTo(typeof(Int16))
+ || converter.CanConvertTo(typeof(Int64))
+ || converter.CanConvertTo(typeof(UInt16))
+ || converter.CanConvertTo(typeof(UInt64))
+ || converter.CanConvertTo(typeof(Byte))
+ || converter.CanConvertTo(typeof(SByte))
+ );
+ }
+
+ /// <summary>
+ /// Determines whether the supplied <paramref name="number"/> can be converted to an integer.
+ /// </summary>
+ /// <param name="number">The object to check.</param>
+ /// <returns>
+ /// <see lang="true"/> if the supplied <paramref name="number"/> can be converted to an integer.
+ /// </returns>
+ public static bool CanConvertToDecimal(object number)
+ {
+ TypeConverter converter = TypeDescriptor.GetConverter(number);
+ return (converter.CanConvertTo(typeof(Single))
+ || converter.CanConvertTo(typeof(Double))
+ || converter.CanConvertTo(typeof(Decimal))
+ );
+ }
+
+ /// <summary>
+ /// Determines whether the supplied <paramref name="number"/> can be converted to a number.
+ /// </summary>
+ /// <param name="number">The object to check.</param>
+ /// <returns>
+ /// <c>true</c> if the specified object is decimal number; otherwise, <c>false</c>.
+ /// </returns>
+ public static bool CanConvertToNumber(object number)
+ {
+ return (CanConvertToInteger(number) || CanConvertToDecimal(number));
+ }
+
/// <summary>
/// Is the supplied <paramref name="number"/> equal to zero (0)?
|