@@ -31,7 +31,7 @@ public static bool IsValueType(this TypeDefinitionHandle handle, MetadataReader
3131
3232 public static bool IsValueType ( this TypeDefinition typeDefinition , MetadataReader reader )
3333 {
34- var baseType = typeDefinition . BaseType ;
34+ EntityHandle baseType = typeDefinition . GetBaseTypeOrNil ( ) ;
3535 if ( baseType . IsNil )
3636 return false ;
3737 if ( baseType . IsKnownType ( reader , KnownTypeCode . Enum ) )
@@ -49,9 +49,10 @@ public static bool IsEnum(this TypeDefinitionHandle handle, MetadataReader reade
4949
5050 public static bool IsEnum ( this TypeDefinition typeDefinition , MetadataReader reader )
5151 {
52- if ( typeDefinition . BaseType . IsNil )
52+ EntityHandle baseType = typeDefinition . GetBaseTypeOrNil ( ) ;
53+ if ( baseType . IsNil )
5354 return false ;
54- return typeDefinition . BaseType . IsKnownType ( reader , KnownTypeCode . Enum ) ;
55+ return baseType . IsKnownType ( reader , KnownTypeCode . Enum ) ;
5556 }
5657
5758 public static bool IsEnum ( this TypeDefinitionHandle handle , MetadataReader reader , out PrimitiveTypeCode underlyingType )
@@ -62,9 +63,10 @@ public static bool IsEnum(this TypeDefinitionHandle handle, MetadataReader reade
6263 public static bool IsEnum ( this TypeDefinition typeDefinition , MetadataReader reader , out PrimitiveTypeCode underlyingType )
6364 {
6465 underlyingType = 0 ;
65- if ( typeDefinition . BaseType . IsNil )
66+ EntityHandle baseType = typeDefinition . GetBaseTypeOrNil ( ) ;
67+ if ( baseType . IsNil )
6668 return false ;
67- if ( ! typeDefinition . BaseType . IsKnownType ( reader , KnownTypeCode . Enum ) )
69+ if ( ! baseType . IsKnownType ( reader , KnownTypeCode . Enum ) )
6870 return false ;
6971 var field = reader . GetFieldDefinition ( typeDefinition . GetFields ( ) . First ( ) ) ;
7072 var blob = reader . GetBlobReader ( field . Signature ) ;
@@ -81,7 +83,7 @@ public static bool IsDelegate(this TypeDefinitionHandle handle, MetadataReader r
8183
8284 public static bool IsDelegate ( this TypeDefinition typeDefinition , MetadataReader reader )
8385 {
84- var baseType = typeDefinition . BaseType ;
86+ var baseType = typeDefinition . GetBaseTypeOrNil ( ) ;
8587 return ! baseType . IsNil && baseType . IsKnownType ( reader , KnownTypeCode . MulticastDelegate ) ;
8688 }
8789
@@ -411,5 +413,14 @@ public int GetTypeFromSpecification(MetadataReader reader, GenericContext generi
411413 return reader . GetTypeSpecification ( handle ) . DecodeSignature ( this , genericContext ) ;
412414 }
413415 }
416+
417+ public static EntityHandle GetBaseTypeOrNil ( this TypeDefinition definition )
418+ {
419+ try {
420+ return definition . BaseType ;
421+ } catch ( BadImageFormatException ) {
422+ return default ;
423+ }
424+ }
414425 }
415426}
0 commit comments