@@ -15,119 +15,8 @@ namespace System
15
15
// IList<U> and IReadOnlyList<U>, where T : U dynamically. See the SZArrayHelper class for details.
16
16
public abstract partial class Array : ICloneable , IList , IStructuralComparable , IStructuralEquatable
17
17
{
18
- // Create instance will create an array
19
- [ RequiresDynamicCode ( "The code for an array of the specified type might not be available." ) ]
20
- public static unsafe Array CreateInstance ( Type elementType , int length )
21
- {
22
- if ( elementType is null )
23
- ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . elementType ) ;
24
- if ( length < 0 )
25
- ThrowHelper . ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum ( ) ;
26
-
27
- RuntimeType ? t = elementType . UnderlyingSystemType as RuntimeType ;
28
- if ( t == null )
29
- ThrowHelper . ThrowArgumentException ( ExceptionResource . Arg_MustBeType , ExceptionArgument . elementType ) ;
30
- return InternalCreate ( ( void * ) t . TypeHandle . Value , 1 , & length , null ) ;
31
- }
32
-
33
- public static unsafe Array CreateInstance ( Type elementType , int length1 , int length2 )
34
- {
35
- if ( elementType is null )
36
- ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . elementType ) ;
37
- if ( length1 < 0 )
38
- ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . length1 , ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
39
- if ( length2 < 0 )
40
- ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . length2 , ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
41
-
42
- RuntimeType ? t = elementType . UnderlyingSystemType as RuntimeType ;
43
- if ( t == null )
44
- ThrowHelper . ThrowArgumentException ( ExceptionResource . Arg_MustBeType , ExceptionArgument . elementType ) ;
45
- int * pLengths = stackalloc int [ 2 ] ;
46
- pLengths [ 0 ] = length1 ;
47
- pLengths [ 1 ] = length2 ;
48
- return InternalCreate ( ( void * ) t . TypeHandle . Value , 2 , pLengths , null ) ;
49
- }
50
-
51
- public static unsafe Array CreateInstance ( Type elementType , int length1 , int length2 , int length3 )
52
- {
53
- if ( elementType is null )
54
- ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . elementType ) ;
55
- if ( length1 < 0 )
56
- ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . length1 , ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
57
- if ( length2 < 0 )
58
- ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . length2 , ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
59
- if ( length3 < 0 )
60
- ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . length3 , ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
61
-
62
- RuntimeType ? t = elementType . UnderlyingSystemType as RuntimeType ;
63
- if ( t == null )
64
- ThrowHelper . ThrowArgumentException ( ExceptionResource . Arg_MustBeType , ExceptionArgument . elementType ) ;
65
- int * pLengths = stackalloc int [ 3 ] ;
66
- pLengths [ 0 ] = length1 ;
67
- pLengths [ 1 ] = length2 ;
68
- pLengths [ 2 ] = length3 ;
69
- return InternalCreate ( ( void * ) t . TypeHandle . Value , 3 , pLengths , null ) ;
70
- }
71
-
72
- [ RequiresDynamicCode ( "The code for an array of the specified type might not be available." ) ]
73
- public static unsafe Array CreateInstance ( Type elementType , params int [ ] lengths )
74
- {
75
- if ( elementType is null )
76
- ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . elementType ) ;
77
- if ( lengths == null )
78
- ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . lengths ) ;
79
- if ( lengths . Length == 0 )
80
- ThrowHelper . ThrowArgumentException ( ExceptionResource . Arg_NeedAtLeast1Rank ) ;
81
-
82
- RuntimeType ? t = elementType . UnderlyingSystemType as RuntimeType ;
83
- if ( t == null )
84
- ThrowHelper . ThrowArgumentException ( ExceptionResource . Arg_MustBeType , ExceptionArgument . elementType ) ;
85
-
86
- // Check to make sure the lengths are all positive. Note that we check this here to give
87
- // a good exception message if they are not; however we check this again inside the execution
88
- // engine's low level allocation function after having made a copy of the array to prevent a
89
- // malicious caller from mutating the array after this check.
90
- for ( int i = 0 ; i < lengths . Length ; i ++ )
91
- if ( lengths [ i ] < 0 )
92
- ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . lengths , i , ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
93
-
94
- fixed ( int * pLengths = & lengths [ 0 ] )
95
- return InternalCreate ( ( void * ) t . TypeHandle . Value , lengths . Length , pLengths , null ) ;
96
- }
97
-
98
- [ RequiresDynamicCode ( "The code for an array of the specified type might not be available." ) ]
99
- public static unsafe Array CreateInstance ( Type elementType , int [ ] lengths , int [ ] lowerBounds )
100
- {
101
- if ( elementType == null )
102
- ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . elementType ) ;
103
- if ( lengths == null )
104
- ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . lengths ) ;
105
- if ( lowerBounds == null )
106
- ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . lowerBounds ) ;
107
- if ( lengths . Length != lowerBounds ! . Length )
108
- ThrowHelper . ThrowArgumentException ( ExceptionResource . Arg_RanksAndBounds ) ;
109
- if ( lengths . Length == 0 )
110
- ThrowHelper . ThrowArgumentException ( ExceptionResource . Arg_NeedAtLeast1Rank ) ;
111
-
112
- RuntimeType ? t = elementType . UnderlyingSystemType as RuntimeType ;
113
- if ( t == null )
114
- ThrowHelper . ThrowArgumentException ( ExceptionResource . Arg_MustBeType , ExceptionArgument . elementType ) ;
115
-
116
- // Check to make sure the lenghts are all positive. Note that we check this here to give
117
- // a good exception message if they are not; however we check this again inside the execution
118
- // engine's low level allocation function after having made a copy of the array to prevent a
119
- // malicious caller from mutating the array after this check.
120
- for ( int i = 0 ; i < lengths . Length ; i ++ )
121
- if ( lengths [ i ] < 0 )
122
- ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . lengths , i , ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
123
-
124
- fixed ( int * pLengths = & lengths [ 0 ] )
125
- fixed ( int * pLowerBounds = & lowerBounds [ 0 ] )
126
- return InternalCreate ( ( void * ) t . TypeHandle . Value , lengths . Length , pLengths , pLowerBounds ) ;
127
- }
128
-
129
18
[ MethodImpl ( MethodImplOptions . InternalCall ) ]
130
- private static extern unsafe Array InternalCreate ( void * elementType , int rank , int * pLengths , int * pLowerBounds ) ;
19
+ private static extern unsafe Array InternalCreate ( RuntimeType elementType , int rank , int * pLengths , int * pLowerBounds ) ;
131
20
132
21
// Copies length elements from sourceArray, starting at index 0, to
133
22
// destinationArray, starting at index 0.
0 commit comments