Skip to content

Commit b8ea873

Browse files
author
Joshua Peterson
authored
Merge pull request #1365 from Unity-Technologies/delegate-enum-covariance
Allow different enums as return type in CreateDelegate (case 1288796)
2 parents 28bfa8c + 9ea12f5 commit b8ea873

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

mcs/class/corlib/System/Delegate.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ private static bool return_type_match (Type delReturnType, Type returnType) {
158158
// Delegate covariance
159159
if (!returnType.IsValueType && delReturnType.IsAssignableFrom (returnType))
160160
returnMatch = true;
161+
else
162+
{
163+
bool isDelArgEnum = delReturnType.IsEnum;
164+
bool isArgEnum = returnType.IsEnum;
165+
if (isArgEnum && isDelArgEnum)
166+
returnMatch = Enum.GetUnderlyingType(delReturnType) == Enum.GetUnderlyingType(returnType);
167+
else if (isDelArgEnum && Enum.GetUnderlyingType(delReturnType) == returnType)
168+
returnMatch = true;
169+
else if (isArgEnum && Enum.GetUnderlyingType(returnType) == delReturnType)
170+
returnMatch = true;
171+
}
161172
}
162173

163174
return returnMatch;

0 commit comments

Comments
 (0)