+2010-05-17 Atsushi Enomoto <atsushi@ximian.com>
+
+ * Enum.cs : TryParse() should raise ArgumentException when the
+ type parameter is not an enum. Fixed bug #604134
+
2010-05-11 Rodrigo Kumpera <rkumpera@novell.com>
* GC.cs: Add EPHEMERON_TOMBSTONE reandonly variable.
public static bool TryParse<TEnum> (string value, bool ignoreCase, out TEnum result) where TEnum : struct
{
Type tenum_type = typeof (TEnum);
+ if (!tenum_type.IsEnum)
+ throw new ArgumentException("TEnum is not an Enum type.", "enumType");
+
result = default (TEnum);
- if (value == null || value.Trim ().Length == 0 || !tenum_type.IsEnum)
+ if (value == null || value.Trim ().Length == 0)
return false;
return Parse (tenum_type, value, ignoreCase, out result);
+2010-05-17 Atsushi Enomoto <atsushi@ximian.com>
+
+ * EnumTest.cs : add test for bug #604134.
+
2010-05-17 Atsushi Enomoto <atsushi@ximian.com>
* StringTest.cs : add test for bug #605094.
Assert.AreEqual (false, success, "#D1");
Assert.AreEqual (TestingEnum.This, result, "#D2");
- // TryParse can accept any struct derived type
- int n;
- success = Enum.TryParse<int> ("31416", out n);
- Assert.AreEqual (false, success, "#E1");
- Assert.AreEqual (0, n, "#E2");
+ // TryParse throws ArgumentException if TEnum is not an enumeration type
+ try {
+ int n;
+ Enum.TryParse<int> ("31416", out n);
+ Assert.Fail ("#E1");
+ } catch (ArgumentException ex) {
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
+ Assert.IsNull (ex.InnerException, "#E3");
+ Assert.IsNotNull (ex.Message, "#E4");
+ Assert.IsNotNull (ex.ParamName, "#E5");
+ Assert.AreEqual ("enumType", ex.ParamName, "#E6");
+ }
}
[Test]