Consider:
object o = 123456U;
ulong l = (ulong) o; // fails
But this:
object o = 123456U;
ulong l = (ulong) (uint) o; // succeeds
The real issue I have is that I'd like to have a function that depending on a parameter type, processes them differently. Such as:
void foo(object o)
{
switch (Type.GetTypeCode(o.GetType()))
{
case TypeCode.UInt32:
case TypeCode.UInt64:
ulong l = (ulong) o;
RunUnsignedIntVersion(l);
break;
case TypeCode.Int32:
case TypeCode.Int64:
long n = (long) o;
RunSignedVersion(n);
break;
}
}
and you can't make the following calls:
foo(123456U);
foo(123456);
I know there are ways to do this using generics. But I'm using .net micro framework and generics are not supported. But any C# 3.0 compiler specific features are supported including anonymous functions.
Edit I'd like to avoid having to handle each type separately. Is there a way this can be done and still have a parameter of object type?