@@ -136,12 +136,13 @@ static MetadataHelperFunctionsExtensions ()
136
136
CoreTypes . Add ( CorElementType . ELEMENT_TYPE_U , typeof ( UIntPtr ) ) ;
137
137
}
138
138
139
- internal static void ReadMethodSignature ( IMetadataImport importer , Instantiation instantiation , ref IntPtr pData , out CorCallingConvention cconv , out Type retType , out List < Type > argTypes )
139
+ internal static void ReadMethodSignature ( IMetadataImport importer , Instantiation instantiation , ref IntPtr pData , out CorCallingConvention cconv , out Type retType , out List < Type > argTypes , out int sentinelIndex )
140
140
{
141
141
cconv = MetadataHelperFunctions . CorSigUncompressCallingConv ( ref pData ) ;
142
142
uint numArgs = 0 ;
143
143
// FIXME: Use number of <T>s.
144
144
uint types = 0 ;
145
+ sentinelIndex = - 1 ;
145
146
if ( ( cconv & CorCallingConvention . Generic ) == CorCallingConvention . Generic )
146
147
types = MetadataHelperFunctions . CorSigUncompressData ( ref pData ) ;
147
148
@@ -150,8 +151,25 @@ internal static void ReadMethodSignature (IMetadataImport importer, Instantiatio
150
151
151
152
retType = ReadType ( importer , instantiation , ref pData ) ;
152
153
argTypes = new List < Type > ( ) ;
153
- for ( int n = 0 ; n < numArgs ; n ++ )
154
+ for ( int n = 0 ; n < numArgs ; n ++ ) {
155
+ CorElementType elemType ;
156
+ unsafe {
157
+ var pByte = ( byte * ) pData ;
158
+ var b = * pByte ;
159
+ elemType = ( CorElementType ) b ;
160
+
161
+ if ( elemType == CorElementType . ELEMENT_TYPE_SENTINEL ) {
162
+ // the case when SENTINEL is presented in a separate position, so we have to increment the pointer
163
+ sentinelIndex = n ;
164
+ pData = ( IntPtr ) ( pByte + 1 ) ;
165
+ }
166
+ else if ( ( elemType & CorElementType . ELEMENT_TYPE_SENTINEL ) == CorElementType . ELEMENT_TYPE_SENTINEL ) {
167
+ // SENTINEL is just a flag on element type, so we haven't to promote the pointer
168
+ sentinelIndex = n ;
169
+ }
170
+ }
154
171
argTypes . Add ( ReadType ( importer , instantiation , ref pData ) ) ;
172
+ }
155
173
}
156
174
157
175
static Type ReadType ( IMetadataImport importer , Instantiation instantiation , ref IntPtr pData )
@@ -163,6 +181,10 @@ static Type ReadType (IMetadataImport importer, Instantiation instantiation, ref
163
181
pData = ( IntPtr ) ( pBytes + 1 ) ;
164
182
}
165
183
184
+ if ( ( et & CorElementType . ELEMENT_TYPE_SENTINEL ) == CorElementType . ELEMENT_TYPE_SENTINEL ) {
185
+ et ^= CorElementType . ELEMENT_TYPE_SENTINEL ; // substract SENTINEL bits from element type to get clean ET
186
+ }
187
+
166
188
switch ( et )
167
189
{
168
190
case CorElementType . ELEMENT_TYPE_VOID : return typeof ( void ) ;
@@ -252,13 +274,26 @@ static Type ReadType (IMetadataImport importer, Instantiation instantiation, ref
252
274
CorCallingConvention cconv ;
253
275
Type retType ;
254
276
List < Type > argTypes ;
255
- ReadMethodSignature ( importer , instantiation , ref pData , out cconv , out retType , out argTypes ) ;
277
+ int sentinelIndex ;
278
+ ReadMethodSignature ( importer , instantiation , ref pData , out cconv , out retType , out argTypes , out sentinelIndex ) ;
256
279
return MetadataExtensions . MakeDelegate ( retType , argTypes ) ;
257
280
}
258
281
259
282
case CorElementType . ELEMENT_TYPE_CMOD_REQD :
260
- case CorElementType . ELEMENT_TYPE_CMOD_OPT :
283
+ case CorElementType . ELEMENT_TYPE_CMOD_OPT : {
284
+ uint token = MetadataHelperFunctions . CorSigUncompressToken ( ref pData ) ;
285
+ return new MetadataType ( importer , ( int ) token ) ;
286
+ }
287
+
288
+ case CorElementType . ELEMENT_TYPE_INTERNAL :
289
+ return typeof ( object ) ; // hack to avoid the exceptions. CLR spec says that this type should never occurs, but it occurs sometimes, mystics
290
+
291
+ case CorElementType . ELEMENT_TYPE_NATIVE_ARRAY_TEMPLATE_ZAPSIG :
292
+ case CorElementType . ELEMENT_TYPE_NATIVE_VALUETYPE_ZAPSIG :
261
293
return ReadType ( importer , instantiation , ref pData ) ;
294
+
295
+ case CorElementType . ELEMENT_TYPE_CANON_ZAPSIG :
296
+ return typeof ( object ) ; // this is representation of __Canon type, but it's inaccessible, using object instead
262
297
}
263
298
throw new NotSupportedException ( "Unknown sig element type: " + et ) ;
264
299
}
0 commit comments