@ -126,18 +126,38 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
@@ -126,18 +126,38 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
private bool IsUsedInMethodDefinition ( MethodDefinition method )
{
return IsUsedInMethodReference ( method )
| | IsUsedInMethodBody ( method . Body )
| | IsUsedInMethodBody ( method )
| | IsUsedInCustomAttributes ( method . CustomAttributes ) ;
}
private bool IsUsedInMethodBody ( MethodBody body )
private bool IsUsedInMethodBody ( MethodDefinition method )
{
if ( b ody = = null )
if ( method . B ody = = null )
return false ;
return body . Instructions . Select ( ins = > ins . Operand as TypeReference ) . Any ( IsUsedInTypeReference )
| | body . Instructions . Select ( ins = > ins . Operand as MethodReference ) . Any ( IsUsedInMethodReference )
| | body . Instructions . Select ( ins = > ins . Operand as FieldReference ) . Any ( IsUsedInFieldReference ) ;
bool found = false ;
foreach ( var instruction in method . Body . Instructions ) {
TypeReference tr = instruction . Operand as TypeReference ;
if ( IsUsedInTypeReference ( tr ) ) {
found = true ;
break ;
}
FieldReference fr = instruction . Operand as FieldReference ;
if ( IsUsedInFieldReference ( fr ) ) {
found = true ;
break ;
}
MethodReference mr = instruction . Operand as MethodReference ;
if ( IsUsedInMethodReference ( mr ) ) {
found = true ;
break ;
}
}
method . Body = null ; // discard body to reduce memory pressure & higher GC gen collections
return found ;
}
private bool IsUsedInMethodParameters ( IEnumerable < ParameterDefinition > parameters )