Skip to content

Commit d97eb38

Browse files
committed
Fix System.Object GetCustomAttributes inherit parameter inconsistency
1 parent c5dc589 commit d97eb38

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ internal static object[] GetCustomAttributes(RuntimeType type, RuntimeType caTyp
12701270
for (int i = 0; i < pcas.Count; i++)
12711271
result.Add(pcas[i]);
12721272

1273-
while (type != (RuntimeType)typeof(object) && type != null)
1273+
while (type != null)
12741274
{
12751275
AddCustomAttributes(ref result, type.GetRuntimeModule(), type.MetadataToken, caType, mustBeInheritable, result);
12761276
mustBeInheritable = true;

src/libraries/System.Runtime/tests/System.Reflection.Tests/CustomAttributeTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,5 +275,15 @@ public void BoxedEnumAttributes()
275275
Assert.Equal(typeof(EnumForArrays[]), att.B3.GetType());
276276
Assert.Equal(EnumForArrays.Two, ((EnumForArrays[])att.B3)[0]);
277277
}
278+
279+
280+
[Fact]
281+
public void SystemObject_GetCustomAttributes_InheritanceConsistency()
282+
{
283+
Type objectType = typeof(object);
284+
object[] attributesWithoutInherit = objectType.GetCustomAttributes(inherit: false);
285+
object[] attributesWithInherit = objectType.GetCustomAttributes(inherit: true);
286+
Assert.Equal(attributesWithoutInherit.Length, attributesWithInherit.Length);
287+
}
278288
}
279289
}

0 commit comments

Comments
 (0)