From 822455e77c2b22badbc74aef972ab427dd826dfb Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 6 Jul 2025 17:45:44 +0800 Subject: [PATCH] Eliminate IEnumerable virtual access --- .../Runtime/CustomAttributes/RuntimeCustomAttributeData.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/CustomAttributes/RuntimeCustomAttributeData.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/CustomAttributes/RuntimeCustomAttributeData.cs index 12b6000851694c..44b163a977cd99 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/CustomAttributes/RuntimeCustomAttributeData.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/CustomAttributes/RuntimeCustomAttributeData.cs @@ -4,6 +4,7 @@ using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; namespace System.Reflection.Runtime.CustomAttributes @@ -166,13 +167,13 @@ protected static CustomAttributeTypedArgument WrapInCustomAttributeTypedArgument } // Handle the array case - if (value is IEnumerable enumerableValue && !(value is string)) + if (value is Array arr) { if (!argumentType.IsArray) throw new BadImageFormatException(); Type reportedElementType = argumentType.GetElementType()!; ArrayBuilder elementTypedArguments = default; - foreach (object elementValue in enumerableValue) + foreach (object elementValue in arr) { CustomAttributeTypedArgument elementTypedArgument = WrapInCustomAttributeTypedArgument(elementValue, reportedElementType); elementTypedArguments.Add(elementTypedArgument); @@ -181,6 +182,7 @@ protected static CustomAttributeTypedArgument WrapInCustomAttributeTypedArgument } else { + Debug.Assert(value is string or (not IEnumerable)); return new CustomAttributeTypedArgument(argumentType, value); } }