@@ -9,62 +9,74 @@ public static class TypeDefinitionRocks {
99
1010 [ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
1111 public static TypeDefinition ? GetBaseType ( this TypeDefinition type ) =>
12- GetBaseType ( type , cache : null ) ;
12+ GetBaseType ( type , resolver : null ) ;
1313
14- public static TypeDefinition ? GetBaseType ( this TypeDefinition type , TypeDefinitionCache ? cache )
14+ public static TypeDefinition ? GetBaseType ( this TypeDefinition type , TypeDefinitionCache ? cache ) =>
15+ GetBaseType ( type , ( IMetadataResolver ? ) cache ) ;
16+
17+ public static TypeDefinition ? GetBaseType ( this TypeDefinition type , IMetadataResolver ? resolver )
1518 {
1619 var bt = type . BaseType ;
1720 if ( bt == null )
1821 return null ;
19- if ( cache != null )
20- return cache . Resolve ( bt ) ;
22+ if ( resolver != null )
23+ return resolver . Resolve ( bt ) ;
2124 return bt . Resolve ( ) ;
2225 }
2326
2427 [ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
2528 public static IEnumerable < TypeDefinition > GetTypeAndBaseTypes ( this TypeDefinition type ) =>
26- GetTypeAndBaseTypes ( type , cache : null ) ;
29+ GetTypeAndBaseTypes ( type , resolver : null ) ;
30+
31+ public static IEnumerable < TypeDefinition > GetTypeAndBaseTypes ( this TypeDefinition type , TypeDefinitionCache ? cache ) =>
32+ GetTypeAndBaseTypes ( type , ( IMetadataResolver ? ) cache ) ;
2733
28- public static IEnumerable < TypeDefinition > GetTypeAndBaseTypes ( this TypeDefinition type , TypeDefinitionCache ? cache )
34+ public static IEnumerable < TypeDefinition > GetTypeAndBaseTypes ( this TypeDefinition type , IMetadataResolver ? resolver )
2935 {
3036 TypeDefinition ? t = type ;
3137
3238 while ( t != null ) {
3339 yield return t ;
34- t = t . GetBaseType ( cache ) ;
40+ t = t . GetBaseType ( resolver ) ;
3541 }
3642 }
3743
3844 [ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
3945 public static IEnumerable < TypeDefinition > GetBaseTypes ( this TypeDefinition type ) =>
40- GetBaseTypes ( type , cache : null ) ;
46+ GetBaseTypes ( type , resolver : null ) ;
4147
42- public static IEnumerable < TypeDefinition > GetBaseTypes ( this TypeDefinition type , TypeDefinitionCache ? cache )
48+ public static IEnumerable < TypeDefinition > GetBaseTypes ( this TypeDefinition type , TypeDefinitionCache ? cache ) =>
49+ GetBaseTypes ( type , ( IMetadataResolver ? ) cache ) ;
50+
51+ public static IEnumerable < TypeDefinition > GetBaseTypes ( this TypeDefinition type , IMetadataResolver ? resolver )
4352 {
4453 TypeDefinition ? t = type ;
4554
46- while ( ( t = t . GetBaseType ( cache ) ) != null ) {
55+ while ( ( t = t . GetBaseType ( resolver ) ) != null ) {
4756 yield return t ;
4857 }
4958 }
5059
5160 [ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
5261 public static bool IsAssignableFrom ( this TypeReference type , TypeReference c ) =>
53- IsAssignableFrom ( type , c , cache : null ) ;
62+ IsAssignableFrom ( type , c , resolver : null ) ;
63+
64+ public static bool IsAssignableFrom ( this TypeReference type , TypeReference c , TypeDefinitionCache ? cache ) =>
65+ IsAssignableFrom ( type , c , ( IMetadataResolver ? ) cache ) ;
5466
55- public static bool IsAssignableFrom ( this TypeReference type , TypeReference c , TypeDefinitionCache ? cache )
67+ public static bool IsAssignableFrom ( this TypeReference type , TypeReference c , IMetadataResolver ? resolver )
5668 {
5769 if ( type . FullName == c . FullName )
5870 return true ;
59- var d = c . Resolve ( ) ;
71+ var d = ( resolver ? . Resolve ( c ) ) ?? c . Resolve ( ) ;
6072 if ( d == null )
6173 return false ;
62- foreach ( var t in d . GetTypeAndBaseTypes ( cache ) ) {
74+ foreach ( var t in d . GetTypeAndBaseTypes ( resolver ) ) {
6375 if ( type . FullName == t . FullName )
6476 return true ;
6577 foreach ( var ifaceImpl in t . Interfaces ) {
6678 var i = ifaceImpl . InterfaceType ;
67- if ( IsAssignableFrom ( type , i , cache ) )
79+ if ( IsAssignableFrom ( type , i , resolver ) )
6880 return true ;
6981 }
7082 }
@@ -73,11 +85,13 @@ public static bool IsAssignableFrom (this TypeReference type, TypeReference c, T
7385
7486 [ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
7587 public static bool IsSubclassOf ( this TypeDefinition type , string typeName ) =>
76- IsSubclassOf ( type , typeName , cache : null ) ;
88+ IsSubclassOf ( type , typeName , resolver : null ) ;
7789
78- public static bool IsSubclassOf ( this TypeDefinition type , string typeName , TypeDefinitionCache ? cache )
90+ public static bool IsSubclassOf ( this TypeDefinition type , string typeName , TypeDefinitionCache ? cache ) =>
91+ IsSubclassOf ( type , typeName , ( IMetadataResolver ? ) cache ) ;
92+ public static bool IsSubclassOf ( this TypeDefinition type , string typeName , IMetadataResolver ? resolver )
7993 {
80- foreach ( var t in type . GetTypeAndBaseTypes ( cache ) ) {
94+ foreach ( var t in type . GetTypeAndBaseTypes ( resolver ) ) {
8195 if ( t . FullName == typeName ) {
8296 return true ;
8397 }
@@ -87,11 +101,14 @@ public static bool IsSubclassOf (this TypeDefinition type, string typeName, Type
87101
88102 [ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
89103 public static bool ImplementsInterface ( this TypeDefinition type , string interfaceName ) =>
90- ImplementsInterface ( type , interfaceName , cache : null ) ;
104+ ImplementsInterface ( type , interfaceName , resolver : null ) ;
91105
92- public static bool ImplementsInterface ( this TypeDefinition type , string interfaceName , TypeDefinitionCache ? cache )
106+ public static bool ImplementsInterface ( this TypeDefinition type , string interfaceName , TypeDefinitionCache ? cache ) =>
107+ ImplementsInterface ( type , interfaceName , ( IMetadataResolver ? ) cache ) ;
108+
109+ public static bool ImplementsInterface ( this TypeDefinition type , string interfaceName , IMetadataResolver ? resolver )
93110 {
94- foreach ( var t in type . GetTypeAndBaseTypes ( cache ) ) {
111+ foreach ( var t in type . GetTypeAndBaseTypes ( resolver ) ) {
95112 foreach ( var i in t . Interfaces ) {
96113 if ( i . InterfaceType . FullName == interfaceName ) {
97114 return true ;
@@ -103,34 +120,43 @@ public static bool ImplementsInterface (this TypeDefinition type, string interfa
103120
104121 [ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
105122 public static string GetPartialAssemblyName ( this TypeReference type ) =>
106- GetPartialAssemblyName ( type , cache : null ) ;
123+ GetPartialAssemblyName ( type , resolver : null ) ;
124+
125+ public static string GetPartialAssemblyName ( this TypeReference type , TypeDefinitionCache ? cache ) =>
126+ GetPartialAssemblyName ( type , ( IMetadataResolver ? ) cache ) ;
107127
108- public static string GetPartialAssemblyName ( this TypeReference type , TypeDefinitionCache ? cache )
128+ public static string GetPartialAssemblyName ( this TypeReference type , IMetadataResolver ? resolver )
109129 {
110- TypeDefinition def = cache != null ? cache . Resolve ( type ) : type . Resolve ( ) ;
130+ TypeDefinition ? def = ( resolver ? . Resolve ( type ) ) ?? type . Resolve ( ) ;
111131 return ( def ?? type ) . Module . Assembly . Name . Name ;
112132 }
113133
114134 [ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
115135 public static string GetPartialAssemblyQualifiedName ( this TypeReference type ) =>
116- GetPartialAssemblyQualifiedName ( type , cache : null ) ;
136+ GetPartialAssemblyQualifiedName ( type , resolver : null ) ;
117137
118- public static string GetPartialAssemblyQualifiedName ( this TypeReference type , TypeDefinitionCache ? cache )
138+ public static string GetPartialAssemblyQualifiedName ( this TypeReference type , TypeDefinitionCache ? cache ) =>
139+ GetPartialAssemblyQualifiedName ( type , ( IMetadataResolver ? ) cache ) ;
140+
141+ public static string GetPartialAssemblyQualifiedName ( this TypeReference type , IMetadataResolver ? resolver )
119142 {
120143 return string . Format ( "{0}, {1}" ,
121144 // Cecil likes to use '/' as the nested type separator, while
122145 // Reflection uses '+' as the nested type separator. Use Reflection.
123146 type . FullName . Replace ( '/' , '+' ) ,
124- type . GetPartialAssemblyName ( cache ) ) ;
147+ type . GetPartialAssemblyName ( resolver ) ) ;
125148 }
126149
127150 [ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
128151 public static string GetAssemblyQualifiedName ( this TypeReference type ) =>
129- GetAssemblyQualifiedName ( type , cache : null ) ;
152+ GetAssemblyQualifiedName ( type , resolver : null ) ;
153+
154+ public static string GetAssemblyQualifiedName ( this TypeReference type , TypeDefinitionCache ? cache ) =>
155+ GetAssemblyQualifiedName ( type , ( IMetadataResolver ? ) cache ) ;
130156
131- public static string GetAssemblyQualifiedName ( this TypeReference type , TypeDefinitionCache ? cache )
157+ public static string GetAssemblyQualifiedName ( this TypeReference type , IMetadataResolver ? resolver )
132158 {
133- TypeDefinition def = cache != null ? cache . Resolve ( type ) : type . Resolve ( ) ;
159+ TypeDefinition ? def = ( resolver ? . Resolve ( type ) ) ?? type . Resolve ( ) ;
134160 return string . Format ( "{0}, {1}" ,
135161 // Cecil likes to use '/' as the nested type separator, while
136162 // Reflection uses '+' as the nested type separator. Use Reflection.
0 commit comments