@@ -65,14 +65,19 @@ public static bool IsAssignableFrom (this TypeReference type, TypeReference c, I
65
65
var d = resolver . Resolve ( c ) ;
66
66
if ( d == null )
67
67
return false ;
68
- foreach ( var t in d . GetTypeAndBaseTypes ( resolver ) ) {
68
+
69
+ TypeDefinition ? t = d ;
70
+
71
+ while ( t is not null ) {
69
72
if ( type . FullName == t . FullName )
70
73
return true ;
71
74
foreach ( var ifaceImpl in t . Interfaces ) {
72
75
var i = ifaceImpl . InterfaceType ;
73
76
if ( IsAssignableFrom ( type , i , resolver ) )
74
77
return true ;
75
78
}
79
+
80
+ t = t . GetBaseType ( resolver ) ;
76
81
}
77
82
return false ;
78
83
}
@@ -84,20 +89,44 @@ public static bool IsSubclassOf (this TypeDefinition type, string typeName, Type
84
89
IsSubclassOf ( type , typeName , ( IMetadataResolver ) cache ) ;
85
90
public static bool IsSubclassOf ( this TypeDefinition type , string typeName , IMetadataResolver resolver )
86
91
{
87
- foreach ( var t in type . GetTypeAndBaseTypes ( resolver ) ) {
92
+ TypeDefinition ? t = type ;
93
+
94
+ while ( t is not null ) {
88
95
if ( t . FullName == typeName ) {
89
96
return true ;
90
97
}
98
+
99
+ t = t . GetBaseType ( resolver ) ;
100
+ }
101
+ return false ;
102
+ }
103
+
104
+ public static bool IsSubclassOfAny ( this TypeDefinition type , IList < string > typeNames , IMetadataResolver resolver , out string ? subclassType )
105
+ {
106
+ subclassType = null ;
107
+
108
+ TypeDefinition ? t = type ;
109
+
110
+ while ( t is not null ) {
111
+ if ( typeNames . Contains ( t . FullName ) ) {
112
+ subclassType = t . FullName ;
113
+ return true ;
114
+ }
115
+
116
+ t = t . GetBaseType ( resolver ) ;
91
117
}
118
+
92
119
return false ;
93
120
}
94
121
95
122
public static bool HasJavaPeer ( this TypeDefinition type , IMetadataResolver resolver )
96
123
{
97
- if ( type . IsInterface && type . ImplementsInterface ( "Java.Interop.IJavaPeerable" , resolver ) )
98
- return true ;
124
+ if ( type . IsInterface )
125
+ return type . ImplementsInterface ( "Java.Interop.IJavaPeerable" , resolver ) ;
99
126
100
- foreach ( var t in type . GetTypeAndBaseTypes ( resolver ) ) {
127
+ TypeDefinition ? t = type ;
128
+
129
+ while ( t is not null ) {
101
130
switch ( t . FullName ) {
102
131
case "Java.Lang.Object" :
103
132
case "Java.Lang.Throwable" :
@@ -107,6 +136,8 @@ public static bool HasJavaPeer (this TypeDefinition type, IMetadataResolver reso
107
136
default :
108
137
break ;
109
138
}
139
+
140
+ t = t . GetBaseType ( resolver ) ;
110
141
}
111
142
return false ;
112
143
}
@@ -119,13 +150,36 @@ public static bool ImplementsInterface (this TypeDefinition type, string interfa
119
150
120
151
public static bool ImplementsInterface ( this TypeDefinition type , string interfaceName , IMetadataResolver resolver )
121
152
{
122
- foreach ( var t in type . GetTypeAndBaseTypes ( resolver ) ) {
153
+ TypeDefinition ? t = type ;
154
+
155
+ while ( t is not null ) {
123
156
foreach ( var i in t . Interfaces ) {
124
157
if ( i . InterfaceType . FullName == interfaceName ) {
125
158
return true ;
126
159
}
127
160
}
161
+
162
+ t = t . GetBaseType ( resolver ) ;
163
+ }
164
+ return false ;
165
+ }
166
+
167
+ public static bool ImplementsAnyInterface ( this TypeDefinition type , IList < string > interfaceNames , IMetadataResolver resolver , out string ? implementedInterface )
168
+ {
169
+ implementedInterface = null ;
170
+ TypeDefinition ? t = type ;
171
+
172
+ while ( t is not null ) {
173
+ foreach ( var i in t . Interfaces ) {
174
+ if ( interfaceNames . Contains ( i . InterfaceType . FullName ) ) {
175
+ implementedInterface = i . InterfaceType . FullName ;
176
+ return true ;
177
+ }
178
+ }
179
+
180
+ t = t . GetBaseType ( resolver ) ;
128
181
}
182
+
129
183
return false ;
130
184
}
131
185
0 commit comments