@@ -8,10 +8,10 @@ namespace Java.Interop.Tools.Cecil {
8
8
public static class TypeDefinitionRocks {
9
9
10
10
[ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
11
- public static TypeDefinition GetBaseType ( this TypeDefinition type ) =>
11
+ public static TypeDefinition ? GetBaseType ( this TypeDefinition type ) =>
12
12
GetBaseType ( type , cache : null ) ;
13
13
14
- public static TypeDefinition GetBaseType ( this TypeDefinition type , TypeDefinitionCache cache )
14
+ public static TypeDefinition ? GetBaseType ( this TypeDefinition type , TypeDefinitionCache ? cache )
15
15
{
16
16
var bt = type . BaseType ;
17
17
if ( bt == null )
@@ -25,30 +25,34 @@ public static TypeDefinition GetBaseType (this TypeDefinition type, TypeDefiniti
25
25
public static IEnumerable < TypeDefinition > GetTypeAndBaseTypes ( this TypeDefinition type ) =>
26
26
GetTypeAndBaseTypes ( type , cache : null ) ;
27
27
28
- public static IEnumerable < TypeDefinition > GetTypeAndBaseTypes ( this TypeDefinition type , TypeDefinitionCache cache )
28
+ public static IEnumerable < TypeDefinition > GetTypeAndBaseTypes ( this TypeDefinition type , TypeDefinitionCache ? cache )
29
29
{
30
- while ( type != null ) {
31
- yield return type ;
32
- type = type . GetBaseType ( cache ) ;
30
+ TypeDefinition ? t = type ;
31
+
32
+ while ( t != null ) {
33
+ yield return t ;
34
+ t = t . GetBaseType ( cache ) ;
33
35
}
34
36
}
35
37
36
38
[ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
37
39
public static IEnumerable < TypeDefinition > GetBaseTypes ( this TypeDefinition type ) =>
38
40
GetBaseTypes ( type , cache : null ) ;
39
41
40
- public static IEnumerable < TypeDefinition > GetBaseTypes ( this TypeDefinition type , TypeDefinitionCache cache )
42
+ public static IEnumerable < TypeDefinition > GetBaseTypes ( this TypeDefinition type , TypeDefinitionCache ? cache )
41
43
{
42
- while ( ( type = type . GetBaseType ( cache ) ) != null ) {
43
- yield return type ;
44
+ TypeDefinition ? t = type ;
45
+
46
+ while ( ( t = t . GetBaseType ( cache ) ) != null ) {
47
+ yield return t ;
44
48
}
45
49
}
46
50
47
51
[ Obsolete ( "Use the TypeDefinitionCache overload for better performance." ) ]
48
52
public static bool IsAssignableFrom ( this TypeReference type , TypeReference c ) =>
49
53
IsAssignableFrom ( type , c , cache : null ) ;
50
54
51
- public static bool IsAssignableFrom ( this TypeReference type , TypeReference c , TypeDefinitionCache cache )
55
+ public static bool IsAssignableFrom ( this TypeReference type , TypeReference c , TypeDefinitionCache ? cache )
52
56
{
53
57
if ( type . FullName == c . FullName )
54
58
return true ;
@@ -71,7 +75,7 @@ public static bool IsAssignableFrom (this TypeReference type, TypeReference c, T
71
75
public static bool IsSubclassOf ( this TypeDefinition type , string typeName ) =>
72
76
IsSubclassOf ( type , typeName , cache : null ) ;
73
77
74
- public static bool IsSubclassOf ( this TypeDefinition type , string typeName , TypeDefinitionCache cache )
78
+ public static bool IsSubclassOf ( this TypeDefinition type , string typeName , TypeDefinitionCache ? cache )
75
79
{
76
80
foreach ( var t in type . GetTypeAndBaseTypes ( cache ) ) {
77
81
if ( t . FullName == typeName ) {
@@ -85,7 +89,7 @@ public static bool IsSubclassOf (this TypeDefinition type, string typeName, Type
85
89
public static bool ImplementsInterface ( this TypeDefinition type , string interfaceName ) =>
86
90
ImplementsInterface ( type , interfaceName , cache : null ) ;
87
91
88
- public static bool ImplementsInterface ( this TypeDefinition type , string interfaceName , TypeDefinitionCache cache )
92
+ public static bool ImplementsInterface ( this TypeDefinition type , string interfaceName , TypeDefinitionCache ? cache )
89
93
{
90
94
foreach ( var t in type . GetTypeAndBaseTypes ( cache ) ) {
91
95
foreach ( var i in t . Interfaces ) {
@@ -101,7 +105,7 @@ public static bool ImplementsInterface (this TypeDefinition type, string interfa
101
105
public static string GetPartialAssemblyName ( this TypeReference type ) =>
102
106
GetPartialAssemblyName ( type , cache : null ) ;
103
107
104
- public static string GetPartialAssemblyName ( this TypeReference type , TypeDefinitionCache cache )
108
+ public static string GetPartialAssemblyName ( this TypeReference type , TypeDefinitionCache ? cache )
105
109
{
106
110
TypeDefinition def = cache != null ? cache . Resolve ( type ) : type . Resolve ( ) ;
107
111
return ( def ?? type ) . Module . Assembly . Name . Name ;
@@ -111,7 +115,7 @@ public static string GetPartialAssemblyName (this TypeReference type, TypeDefini
111
115
public static string GetPartialAssemblyQualifiedName ( this TypeReference type ) =>
112
116
GetPartialAssemblyQualifiedName ( type , cache : null ) ;
113
117
114
- public static string GetPartialAssemblyQualifiedName ( this TypeReference type , TypeDefinitionCache cache )
118
+ public static string GetPartialAssemblyQualifiedName ( this TypeReference type , TypeDefinitionCache ? cache )
115
119
{
116
120
return string . Format ( "{0}, {1}" ,
117
121
// Cecil likes to use '/' as the nested type separator, while
@@ -124,7 +128,7 @@ public static string GetPartialAssemblyQualifiedName (this TypeReference type, T
124
128
public static string GetAssemblyQualifiedName ( this TypeReference type ) =>
125
129
GetAssemblyQualifiedName ( type , cache : null ) ;
126
130
127
- public static string GetAssemblyQualifiedName ( this TypeReference type , TypeDefinitionCache cache )
131
+ public static string GetAssemblyQualifiedName ( this TypeReference type , TypeDefinitionCache ? cache )
128
132
{
129
133
TypeDefinition def = cache != null ? cache . Resolve ( type ) : type . Resolve ( ) ;
130
134
return string . Format ( "{0}, {1}" ,
@@ -134,7 +138,7 @@ public static string GetAssemblyQualifiedName (this TypeReference type, TypeDefi
134
138
( def ?? type ) . Module . Assembly . Name . FullName ) ;
135
139
}
136
140
137
- public static TypeDefinition GetNestedType ( this TypeDefinition type , string name )
141
+ public static TypeDefinition ? GetNestedType ( this TypeDefinition type , string name )
138
142
{
139
143
if ( type == null )
140
144
return null ;
@@ -147,7 +151,7 @@ public static TypeDefinition GetNestedType (this TypeDefinition type, string nam
147
151
}
148
152
149
153
// Note: this is not recursive, so it will not find nested types.
150
- public static TypeDefinition FindType ( this ModuleDefinition module , string name )
154
+ public static TypeDefinition ? FindType ( this ModuleDefinition module , string name )
151
155
{
152
156
if ( module == null )
153
157
return null ;
0 commit comments