Skip to content

Commit 3d4bb39

Browse files
vargazjoncham
authored andcommitted
[bcl] Allow conversion from enums and their basetypes in both directions with Delegate.CreateDelegate (). Fixes mono#6255. (case 977917)
1 parent 2c936e0 commit 3d4bb39

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

mcs/class/corlib/System/Delegate.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ private static bool arg_type_match (Type delArgType, Type argType) {
134134
if (!match) {
135135
if (delArgType.IsEnum && Enum.GetUnderlyingType (delArgType) == argType)
136136
match = true;
137+
else if (argType.IsEnum && Enum.GetUnderlyingType (argType) == delArgType)
138+
match = true;
137139
}
138140

139141
return match;

mcs/class/corlib/Test/System/DelegateTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,23 @@ public void EnumBaseTypeConversion () {
13951395
Assert.IsTrue (d (0, 0));
13961396
}
13971397

1398+
[Test]
1399+
public void EnumBaseTypeConversion2 () {
1400+
Func<Enum22, int> dm = EnumArg;
1401+
var d = (Func<int, int>)Delegate.CreateDelegate (typeof (Func<int, int>), dm.Method);
1402+
Assert.AreEqual (1, d (1));
1403+
}
1404+
1405+
public enum Enum22 {
1406+
none,
1407+
one,
1408+
two
1409+
}
1410+
1411+
public static int EnumArg (Enum22 e) {
1412+
return (int)e;
1413+
}
1414+
13981415
#if !MONOTOUCH && !FULL_AOT_RUNTIME
13991416
public static void DynInvokeWithClosedFirstArg (object a, object b)
14001417
{

0 commit comments

Comments
 (0)