[Mono-list] ChangeType issues...

Mariano Alarcon marianoa@itcsoluciones.com
Wed, 06 Oct 2004 12:03:08 -0300


I have this small function:

public static object Parse(object from, Type toType, object defaultValue) {
    try {
        return Convert.ChangeType(from, toType);
    } catch (Exception) {
        return defaultValue;
    }
}

I use it in Ms.net to convert between types. For example:

int convertedInt = (int) Parse("123", typeof(int), 0);   // returns 123
int convertedInt = (int) Parse("hello", typeof(int), 0); // returns   0
int convertedInt = (int) Parse(null, typeof(int), 0);    // returns   0

So far so good.

Now with mono 1.0 the last statement generates an exception because 
Parse returns null instead of 0. That means that the conversion from 
null to int succeeds and the result is null (That's wrong right?).

Could someone tell me if this issue has been fixed in 1.0.2 or if I 
should file a bug report? Thank you.