typeof (DateTime), // 16 TypeCode.DateTime
null, // 17 null.
typeof (String), // 18 TypeCode.String
+ typeof (Enum)
};
// Function to convert an object to another type and return
if (conversionType == conversionTable[18]) // 18 TypeCode.String
return convertValue.ToString (provider);
+ if (conversionType == conversionTable[19] && value is Enum) // System.Enum
+ return value;
+
if (try_target_to_type)
return convertValue.ToType (conversionType, provider);
}
{
if (targetType == null)
throw new ArgumentNullException ("targetType");
- if (targetType == typeof (string))
- return ToString (provider);
- return Convert.ToType (Value, targetType, provider, false);
+
+ return Convert.ToType (this, targetType, provider, false);
}
ushort IConvertible.ToUInt16 (IFormatProvider provider)
}
[Test]
- public void ConvertToStringType ()
+ public void IConvertible_Valid ()
{
- Assert.AreEqual ("This", ((IConvertible) TestingEnum.This).ToType (typeof (string), null));
+ IConvertible ic = TestingEnum.This;
+ Assert.AreEqual ("This", ic.ToType (typeof (string), null), "#1");
+ Assert.AreEqual (TestingEnum.This, ic.ToType (typeof (TestingEnum), null), "#2");
+ Assert.AreEqual (TestingEnum.This, ic.ToType (typeof (Enum), null), "#3");
}
[Test]