From 7a7a1461a0492908853b1bbb682271640943db9b Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Mon, 30 Nov 2020 14:58:06 -0500 Subject: [PATCH] Allow different enums as return type in CreateDelegate (case 1288796) Allow `CreateDelegate` to have return type covariance with methods that return `enum` or `int` types. This is from the upstream change at https://github.com/mono/mono/commit/122494330d635205b0a8766deaeafd0d79bd3d60. --- mcs/class/corlib/System/Delegate.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mcs/class/corlib/System/Delegate.cs b/mcs/class/corlib/System/Delegate.cs index 958b70ce816..7447b4a9e01 100644 --- a/mcs/class/corlib/System/Delegate.cs +++ b/mcs/class/corlib/System/Delegate.cs @@ -158,6 +158,17 @@ namespace System // Delegate covariance if (!returnType.IsValueType && delReturnType.IsAssignableFrom (returnType)) returnMatch = true; + else + { + bool isDelArgEnum = delReturnType.IsEnum; + bool isArgEnum = returnType.IsEnum; + if (isArgEnum && isDelArgEnum) + returnMatch = Enum.GetUnderlyingType(delReturnType) == Enum.GetUnderlyingType(returnType); + else if (isDelArgEnum && Enum.GetUnderlyingType(delReturnType) == returnType) + returnMatch = true; + else if (isArgEnum && Enum.GetUnderlyingType(returnType) == delReturnType) + returnMatch = true; + } } return returnMatch; -- GitLab