diff options
Diffstat (limited to 'src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/Helpers.cs')
-rw-r--r-- | src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/Helpers.cs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/Helpers.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/Helpers.cs index 90943008c..5d851fb09 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/Helpers.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/Helpers.cs @@ -189,8 +189,14 @@ namespace System.Reflection.Runtime.General object instantiatedAttribute = cad.Instantiate(); attributes.Add(instantiatedAttribute); } + + // This is here for desktop compatibility. ICustomAttribute.GetCustomAttributes() normally returns an array of the + // exact attribute type requested except in two cases: when the passed in type is an open type and when + // it is a value type. In these two cases, it returns an array of type Object[]. + bool useObjectArray = actualElementType.ContainsGenericParameters || actualElementType.IsValueType; int count = attributes.Count; - object[] result = (object[])Array.CreateInstance(actualElementType, count); + object[] result = useObjectArray ? new object[count] : (object[])Array.CreateInstance(actualElementType, count); + attributes.CopyTo(result, 0); return result; } |