@@ -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,26 @@ 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 ) ;
91
100
}
92
101
return false ;
93
102
}
94
103
95
104
public static bool HasJavaPeer ( this TypeDefinition type , IMetadataResolver resolver )
96
105
{
97
- if ( type . IsInterface && type . ImplementsInterface ( "Java.Interop.IJavaPeerable" , resolver ) )
98
- return true ;
106
+ if ( type . IsInterface )
107
+ return type . ImplementsInterface ( "Java.Interop.IJavaPeerable" , resolver ) ;
99
108
100
- foreach ( var t in type . GetTypeAndBaseTypes ( resolver ) ) {
109
+ TypeDefinition ? t = type ;
110
+
111
+ while ( t is not null ) {
101
112
switch ( t . FullName ) {
102
113
case "Java.Lang.Object" :
103
114
case "Java.Lang.Throwable" :
@@ -107,6 +118,8 @@ public static bool HasJavaPeer (this TypeDefinition type, IMetadataResolver reso
107
118
default :
108
119
break ;
109
120
}
121
+
122
+ t = t . GetBaseType ( resolver ) ;
110
123
}
111
124
return false ;
112
125
}
@@ -119,12 +132,16 @@ public static bool ImplementsInterface (this TypeDefinition type, string interfa
119
132
120
133
public static bool ImplementsInterface ( this TypeDefinition type , string interfaceName , IMetadataResolver resolver )
121
134
{
122
- foreach ( var t in type . GetTypeAndBaseTypes ( resolver ) ) {
135
+ TypeDefinition ? t = type ;
136
+
137
+ while ( t is not null ) {
123
138
foreach ( var i in t . Interfaces ) {
124
139
if ( i . InterfaceType . FullName == interfaceName ) {
125
140
return true ;
126
141
}
127
142
}
143
+
144
+ t = t . GetBaseType ( resolver ) ;
128
145
}
129
146
return false ;
130
147
}
0 commit comments