@@ -28,12 +28,7 @@ public static CustomAttributeInfo CreateInfo(CustomAttributeData attribute)
2828 {
2929 Debug . Assert ( attribute != null , "attribute != null" ) ;
3030
31- // .NET Core does not provide CustomAttributeData.Constructor, so we'll implement it
32- // by finding a constructor ourselves
33- Type [ ] constructorArgTypes ;
34- object [ ] constructorArgs ;
35- GetArguments ( attribute . ConstructorArguments , out constructorArgTypes , out constructorArgs ) ;
36- var constructor = attribute . AttributeType . GetConstructor ( constructorArgTypes ) ;
31+ object [ ] constructorArgs = GetArguments ( attribute . ConstructorArguments ) ;
3732
3833 PropertyInfo [ ] properties ;
3934 object [ ] propertyValues ;
@@ -43,26 +38,14 @@ public static CustomAttributeInfo CreateInfo(CustomAttributeData attribute)
4338 attribute . AttributeType ,
4439 attribute . NamedArguments , out properties , out propertyValues , out fields , out fieldValues ) ;
4540
46- return new CustomAttributeInfo ( constructor ,
41+ return new CustomAttributeInfo ( attribute . Constructor ,
4742 constructorArgs ,
4843 properties ,
4944 propertyValues ,
5045 fields ,
5146 fieldValues ) ;
5247 }
5348
54- private static void GetArguments ( IList < CustomAttributeTypedArgument > constructorArguments ,
55- out Type [ ] constructorArgTypes , out object [ ] constructorArgs )
56- {
57- constructorArgTypes = new Type [ constructorArguments . Count ] ;
58- constructorArgs = new object [ constructorArguments . Count ] ;
59- for ( var i = 0 ; i < constructorArguments . Count ; i ++ )
60- {
61- constructorArgTypes [ i ] = constructorArguments [ i ] . ArgumentType ;
62- constructorArgs [ i ] = ReadAttributeValue ( constructorArguments [ i ] ) ;
63- }
64- }
65-
6649 private static object [ ] GetArguments ( IList < CustomAttributeTypedArgument > constructorArguments )
6750 {
6851 var arguments = new object [ constructorArguments . Count ] ;
@@ -77,15 +60,18 @@ private static object[] GetArguments(IList<CustomAttributeTypedArgument> constru
7760 private static object ReadAttributeValue ( CustomAttributeTypedArgument argument )
7861 {
7962 var value = argument . Value ;
80- if ( argument . ArgumentType . IsArray == false )
63+
64+ if ( argument . ArgumentType . IsArray && value is IList < CustomAttributeTypedArgument > values )
8165 {
82- return value ;
66+ // `CustomAttributeInfo` represents array values as `ReadOnlyCollection<CustomAttributeTypedArgument>`,
67+ // but `CustomAttributeBuilder` will require plain arrays, so we need a (recursive) conversion:
68+ var arguments = GetArguments ( values ) ;
69+ var array = new object [ arguments . Length ] ;
70+ arguments . CopyTo ( array , 0 ) ;
71+ return array ;
8372 }
84- //special case for handling arrays in attributes
85- var arguments = GetArguments ( ( IList < CustomAttributeTypedArgument > ) value ) ;
86- var array = new object [ arguments . Length ] ;
87- arguments . CopyTo ( array , 0 ) ;
88- return array ;
73+
74+ return value ;
8975 }
9076
9177 private static void GetSettersAndFields ( Type attributeType , IEnumerable < CustomAttributeNamedArgument > namedArguments ,
0 commit comments