Enable test in System.Reflection.Extensions (#6445) (#34815)
authorThorsten Reichert <ThorstenReichert@users.noreply.github.com>
Sat, 11 Apr 2020 09:48:57 +0000 (11:48 +0200)
committerGitHub <noreply@github.com>
Sat, 11 Apr 2020 09:48:57 +0000 (11:48 +0200)
Fixes #6445.

Enabled GetCustom_Attribute_On_Return_Parameter_On_Parent_Method in System.Reflection.Extension Tests.

Note: had to change the attribute to inherit true on the parent class, so that the attribute could actually be retrieved from the derived class

* port CoreClr fix (https://github.com/dotnet/coreclr/pull/6745) to Mono

apply the same check for parameter position = -1 in Mono as is done in CoreClr

src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_ParameterInfo.cs [moved from src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_ParamterInfo.cs with 98% similarity]
src/libraries/System.Reflection.Extensions/tests/System.Reflection.Extensions.Tests.csproj
src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs

@@ -238,13 +238,12 @@ namespace System.Reflection.Tests
         }
 
         [Fact]
-        [ActiveIssue(@"https://github.com/dotnet/runtime/issues/6445")]
         public void GetCustom_Attribute_On_Return_Parameter_On_Parent_Method()
         {
             Type type = typeof(TestClass_P_Derived);
             MethodInfo miWithReturnAttribute = type.GetTypeInfo().GetDeclaredMethod("methodWithReturnAttribute");
             ParameterInfo returnParameter = miWithReturnAttribute.ReturnParameter;
-            MyAttribute_Single_P attribute = CustomAttributeExtensions.GetCustomAttribute<MyAttribute_Single_P>(returnParameter, inherit: true);
+            MyAttribute_Single_Inherited_P attribute = CustomAttributeExtensions.GetCustomAttribute<MyAttribute_Single_Inherited_P>(returnParameter, inherit: true);
             Assert.NotNull(attribute);
         }
     }
@@ -294,7 +293,7 @@ namespace System.Reflection.Tests
                                       MyAttribute_AllowMultiple_Inherited_P("multiple")] int param)
         { }
 
-        [return: MyAttribute_Single_P("single")]
+        [return: MyAttribute_Single_Inherited_P("single")]
         public virtual byte methodWithReturnAttribute() { return 0; }
     }
 
index c0ed6a4..d9932a1 100644 (file)
@@ -12,7 +12,7 @@
     <Compile Include="GetCustomAttributes_Assembly.cs" />
     <Compile Include="GetCustomAttributes_Compat.cs" />
     <Compile Include="GetCustomAttributes_MemberInfo.cs" />
-    <Compile Include="GetCustomAttributes_ParamterInfo.cs" />
+    <Compile Include="GetCustomAttributes_ParameterInfo.cs" />
     <Compile Include="ReflectionTestExtensions.cs" />
     <Compile Include="RuntimeReflectionExtensionTests.cs" />
     <Compile Include="RuntimeReflectionExtensionTestsWithQuirks.cs" />
index 1614418..e218880 100644 (file)
@@ -667,7 +667,10 @@ namespace System.Reflection
                     MethodInfo bmethod = ((RuntimeMethodInfo)method).GetBaseMethod();
                     if (bmethod == method)
                         return null;
-                    return bmethod.GetParameters()[parinfo.Position];
+                    int position = parinfo.Position;
+                    if (position == -1)
+                        return bmethod.ReturnParameter;
+                    return bmethod.GetParameters()[position];
                 }
             }
             /*