@@ -9,62 +9,74 @@ public static class TypeDefinitionRocks {
9
9
10
10
[ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
11
11
public static TypeDefinition ? GetBaseType ( this TypeDefinition type ) =>
12
- GetBaseType ( type , cache : null ) ;
12
+ GetBaseType ( type , resolver : null ) ;
13
13
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 )
15
18
{
16
19
var bt = type . BaseType ;
17
20
if ( bt == null )
18
21
return null ;
19
- if ( cache != null )
20
- return cache . Resolve ( bt ) ;
22
+ if ( resolver != null )
23
+ return resolver . Resolve ( bt ) ;
21
24
return bt . Resolve ( ) ;
22
25
}
23
26
24
27
[ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
25
28
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 ) ;
27
33
28
- public static IEnumerable < TypeDefinition > GetTypeAndBaseTypes ( this TypeDefinition type , TypeDefinitionCache ? cache )
34
+ public static IEnumerable < TypeDefinition > GetTypeAndBaseTypes ( this TypeDefinition type , IMetadataResolver ? resolver )
29
35
{
30
36
TypeDefinition ? t = type ;
31
37
32
38
while ( t != null ) {
33
39
yield return t ;
34
- t = t . GetBaseType ( cache ) ;
40
+ t = t . GetBaseType ( resolver ) ;
35
41
}
36
42
}
37
43
38
44
[ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
39
45
public static IEnumerable < TypeDefinition > GetBaseTypes ( this TypeDefinition type ) =>
40
- GetBaseTypes ( type , cache : null ) ;
46
+ GetBaseTypes ( type , resolver : null ) ;
41
47
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 )
43
52
{
44
53
TypeDefinition ? t = type ;
45
54
46
- while ( ( t = t . GetBaseType ( cache ) ) != null ) {
55
+ while ( ( t = t . GetBaseType ( resolver ) ) != null ) {
47
56
yield return t ;
48
57
}
49
58
}
50
59
51
60
[ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
52
61
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 ) ;
54
66
55
- public static bool IsAssignableFrom ( this TypeReference type , TypeReference c , TypeDefinitionCache ? cache )
67
+ public static bool IsAssignableFrom ( this TypeReference type , TypeReference c , IMetadataResolver ? resolver )
56
68
{
57
69
if ( type . FullName == c . FullName )
58
70
return true ;
59
- var d = c . Resolve ( ) ;
71
+ var d = ( resolver ? . Resolve ( c ) ) ?? c . Resolve ( ) ;
60
72
if ( d == null )
61
73
return false ;
62
- foreach ( var t in d . GetTypeAndBaseTypes ( cache ) ) {
74
+ foreach ( var t in d . GetTypeAndBaseTypes ( resolver ) ) {
63
75
if ( type . FullName == t . FullName )
64
76
return true ;
65
77
foreach ( var ifaceImpl in t . Interfaces ) {
66
78
var i = ifaceImpl . InterfaceType ;
67
- if ( IsAssignableFrom ( type , i , cache ) )
79
+ if ( IsAssignableFrom ( type , i , resolver ) )
68
80
return true ;
69
81
}
70
82
}
@@ -73,11 +85,13 @@ public static bool IsAssignableFrom (this TypeReference type, TypeReference c, T
73
85
74
86
[ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
75
87
public static bool IsSubclassOf ( this TypeDefinition type , string typeName ) =>
76
- IsSubclassOf ( type , typeName , cache : null ) ;
88
+ IsSubclassOf ( type , typeName , resolver : null ) ;
77
89
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 )
79
93
{
80
- foreach ( var t in type . GetTypeAndBaseTypes ( cache ) ) {
94
+ foreach ( var t in type . GetTypeAndBaseTypes ( resolver ) ) {
81
95
if ( t . FullName == typeName ) {
82
96
return true ;
83
97
}
@@ -87,11 +101,14 @@ public static bool IsSubclassOf (this TypeDefinition type, string typeName, Type
87
101
88
102
[ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
89
103
public static bool ImplementsInterface ( this TypeDefinition type , string interfaceName ) =>
90
- ImplementsInterface ( type , interfaceName , cache : null ) ;
104
+ ImplementsInterface ( type , interfaceName , resolver : null ) ;
91
105
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 )
93
110
{
94
- foreach ( var t in type . GetTypeAndBaseTypes ( cache ) ) {
111
+ foreach ( var t in type . GetTypeAndBaseTypes ( resolver ) ) {
95
112
foreach ( var i in t . Interfaces ) {
96
113
if ( i . InterfaceType . FullName == interfaceName ) {
97
114
return true ;
@@ -103,34 +120,43 @@ public static bool ImplementsInterface (this TypeDefinition type, string interfa
103
120
104
121
[ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
105
122
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 ) ;
107
127
108
- public static string GetPartialAssemblyName ( this TypeReference type , TypeDefinitionCache ? cache )
128
+ public static string GetPartialAssemblyName ( this TypeReference type , IMetadataResolver ? resolver )
109
129
{
110
- TypeDefinition def = cache != null ? cache . Resolve ( type ) : type . Resolve ( ) ;
130
+ TypeDefinition ? def = ( resolver ? . Resolve ( type ) ) ?? type . Resolve ( ) ;
111
131
return ( def ?? type ) . Module . Assembly . Name . Name ;
112
132
}
113
133
114
134
[ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
115
135
public static string GetPartialAssemblyQualifiedName ( this TypeReference type ) =>
116
- GetPartialAssemblyQualifiedName ( type , cache : null ) ;
136
+ GetPartialAssemblyQualifiedName ( type , resolver : null ) ;
117
137
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 )
119
142
{
120
143
return string . Format ( "{0}, {1}" ,
121
144
// Cecil likes to use '/' as the nested type separator, while
122
145
// Reflection uses '+' as the nested type separator. Use Reflection.
123
146
type . FullName . Replace ( '/' , '+' ) ,
124
- type . GetPartialAssemblyName ( cache ) ) ;
147
+ type . GetPartialAssemblyName ( resolver ) ) ;
125
148
}
126
149
127
150
[ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
128
151
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 ) ;
130
156
131
- public static string GetAssemblyQualifiedName ( this TypeReference type , TypeDefinitionCache ? cache )
157
+ public static string GetAssemblyQualifiedName ( this TypeReference type , IMetadataResolver ? resolver )
132
158
{
133
- TypeDefinition def = cache != null ? cache . Resolve ( type ) : type . Resolve ( ) ;
159
+ TypeDefinition ? def = ( resolver ? . Resolve ( type ) ) ?? type . Resolve ( ) ;
134
160
return string . Format ( "{0}, {1}" ,
135
161
// Cecil likes to use '/' as the nested type separator, while
136
162
// Reflection uses '+' as the nested type separator. Use Reflection.
0 commit comments