diff options
author | Maxim Lipnin <v-maxlip@microsoft.com> | 2018-10-04 10:07:49 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2018-10-04 10:34:59 +0300 |
commit | 0fc965a5410ad2761d33eda4e81cebc4b4e08393 (patch) | |
tree | 889b6ac0a14e9bc2422b4e3de285d66f136bf2ea | |
parent | efd29b5cf854679349066e22ef9038b8cfe76d94 (diff) |
[Reflection] Use actual type of element if constructor of custom attribute typed argument takes an array of objects.
-rw-r--r-- | src/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs | 7 |
1 files 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 <CustomAttributeTypedArgument>(new_value); } #endif |