From 0fc965a5410ad2761d33eda4e81cebc4b4e08393 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Thu, 4 Oct 2018 10:07:49 +0300 Subject: [Reflection] Use actual type of element if constructor of custom attribute typed argument takes an array of objects. --- .../src/System/Reflection/CustomAttributeTypedArgument.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs b/src/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs index dff766236..8f09f8236 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs @@ -31,8 +31,11 @@ namespace System.Reflection if (value is Array a) { Type etype = a.GetType().GetElementType(); CustomAttributeTypedArgument[] new_value = new CustomAttributeTypedArgument[a.GetLength(0)]; - for (int i = 0; i < new_value.Length; ++i) - new_value[i] = new CustomAttributeTypedArgument(etype, a.GetValue(i)); + for (int i = 0; i < new_value.Length; ++i) { + var val = a.GetValue (i); + var elemType = etype == typeof (System.Object) ? val.GetType () : etype; + new_value[i] = new CustomAttributeTypedArgument (elemType, val); + } Value = new System.Collections.ObjectModel.ReadOnlyCollection (new_value); } #endif -- cgit v1.2.3