Re: IsNumeric
- From: "sck10" <sck10@xxxxxxxxxxxxx>
- Date: Thu, 7 Sep 2006 07:55:44 -0500
Thanks Walter. I was rummaging around the Reflector tool and came these
three definitions. The first is from the definition from "Main" that you
provided. Can you help me with the last two? So my understanding is that I
can use example #1 for my needs?
Example #1
========
public static bool IsNumeric(object Expression)
{
IConvertible convertible1 = Expression as IConvertible;
if (convertible1 != null)
{
switch (convertible1.GetTypeCode())
{
case TypeCode.Boolean:
return true;
case TypeCode.Char:
case TypeCode.String:
{
double num1;
string text1 = convertible1.ToString(null);
try
{
long num2;
if (Utils.IsHexOrOctValue(text1, ref num2))
{
return true;
}
}
catch (FormatException)
{
return false;
}
return Conversions.TryParseDouble(text1, ref num1);
}
case TypeCode.SByte:
case TypeCode.Byte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
return true;
}
}
return false;
}
Example #2
========
internal static bool IsNumeric(StorageType type)
{
if (!ExpressionNode.IsFloat(type))
{
return ExpressionNode.IsInteger(type);
}
return true;
}
Example #3
========
public static bool IsNumeric(object Expression)
{
double num1;
IConvertible convertible1 = Expression as IConvertible;
if (convertible1 == null)
{
char[] chArray1 = Expression as char[];
if (chArray1 != null)
{
Expression = new string(chArray1);
}
else
{
return false;
}
}
TypeCode code1 = convertible1.GetTypeCode();
if ((code1 != TypeCode.String) && (code1 != TypeCode.Char))
{
return Information.IsOldNumericTypeCode(code1);
}
string text1 = convertible1.ToString(null);
try
{
long num2;
if (Utils.IsHexOrOctValue(text1, ref num2))
{
return true;
}
}
catch (StackOverflowException exception1)
{
throw exception1;
}
catch (OutOfMemoryException exception2)
{
throw exception2;
}
catch (ThreadAbortException exception3)
{
throw exception3;
}
catch (Exception)
{
return false;
}
return DoubleType.TryParse(text1, ref num1);
}
"Walter Wang [MSFT]" <wawang@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:Yjx5gT8zGHA.4548@xxxxxxxxxxxxxxxxxxxxxxxx
Hi sck10,
Thank you for your quick reply.
Here's the steps to get the source code of IsNumeric:
1) Create a simple VB.NET console application, type in following code:
Sub Main()
Dim s As String = "1.234"
If IsNumeric(s) Then
Console.WriteLine("s is numeric")
End If
s = "2006/9/1"
If IsDate(s) Then
Console.WriteLine("s is date")
End If
End Sub
2) Build it; in Reflector, open the generated exe; find the Main function,
double click it to see its disassembled code (make sure you selected "C#"
in the toolbar combobox):
[STAThread]
public static void Main()
{
string text1 = "1.234";
if (Versioned.IsNumeric(text1))
{
Console.WriteLine("s is numeric");
}
text1 = "2006/9/1";
if (Information.IsDate(text1))
{
Console.WriteLine("s is date");
}
}
3) Click on the "IsNumeric" function to navigate to its source. You will
learn that it's located in
Microsoft.VisualBasic.CompilerServices.Versioned
as a static method, so you can reference Microsoft.VisualBasic.dll in your
C# project and use this method directly; or you can write your version of
IsNumeric use the disassembled code as reference.
Hope this helps. Please feel free to post here if anything is unclear.
Regards,
Walter Wang (wawang@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
.
- Follow-Ups:
- Re: IsNumeric
- From: Walter Wang [MSFT]
- Re: IsNumeric
- References:
- IsNumeric
- From: sck10
- RE: IsNumeric
- From: Walter Wang [MSFT]
- Re: IsNumeric
- From: sck10
- Re: IsNumeric
- From: Walter Wang [MSFT]
- IsNumeric
- Prev by Date: Re: DIV runat=server vs PANEL
- Next by Date: Re: WSDL Generated Proxy Classes?
- Previous by thread: Re: IsNumeric
- Next by thread: Re: IsNumeric
- Index(es):
Loading