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(objec t Expression)
{
IConvertible convertible1 = Expression as IConvertible;
if (convertible1 != null)
{
switch (convertible1.G etTypeCode())
{
case TypeCode.Boolea n:
return true;
case TypeCode.Char:
case TypeCode.String :
{
double num1;
string text1 = convertible1.To String(null);
try
{
long num2;
if (Utils.IsHexOrO ctValue(text1, ref num2))
{
return true;
}
}
catch (FormatExceptio n)
{
return false;
}
return Conversions.Try ParseDouble(tex t1, 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.Decima l:
return true;
}
}
return false;
}
Example #2
========
internal static bool IsNumeric(Stora geType type)
{
if (!ExpressionNod e.IsFloat(type) )
{
return ExpressionNode. IsInteger(type) ;
}
return true;
}
Example #3
========
public static bool IsNumeric(objec t 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.Ge tTypeCode();
if ((code1 != TypeCode.String ) && (code1 != TypeCode.Char))
{
return Information.IsO ldNumericTypeCo de(code1);
}
string text1 = convertible1.To String(null);
try
{
long num2;
if (Utils.IsHexOrO ctValue(text1, ref num2))
{
return true;
}
}
catch (StackOverflowE xception exception1)
{
throw exception1;
}
catch (OutOfMemoryExc eption exception2)
{
throw exception2;
}
catch (ThreadAbortExc eption exception3)
{
throw exception3;
}
catch (Exception)
{
return false;
}
return DoubleType.TryP arse(text1, ref num1);
}
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:Yj******** ******@TK2MSFTN GXA01.phx.gbl.. .
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.WriteLi ne("s is numeric")
End If
s = "2006/9/1"
If IsDate(s) Then
Console.WriteLi ne("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.IsNu meric(text1))
{
Console.WriteLi ne("s is numeric");
}
text1 = "2006/9/1";
if (Information.Is Date(text1))
{
Console.WriteLi ne("s is date");
}
}
3) Click on the "IsNumeric" function to navigate to its source. You will
learn that it's located in
Microsoft.Visua lBasic.Compiler Services.Versio ned
as a static method, so you can reference Microsoft.Visua lBasic.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 (wa****@online. microsoft.com, 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.