|
|
|
@ -45,6 +45,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
@@ -45,6 +45,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
|
|
|
|
|
Debug.Assert(analyzedSymbol is IMethod); |
|
|
|
|
|
|
|
|
|
var analyzedMethod = (IMethod)analyzedSymbol; |
|
|
|
|
var analyzedBaseMethod = (IMethod)InheritanceHelper.GetBaseMember(analyzedMethod); |
|
|
|
|
var mapping = context.Language |
|
|
|
|
.GetCodeMappingInfo(analyzedMethod.ParentModule.PEFile, |
|
|
|
|
analyzedMethod.DeclaringTypeDefinition.MetadataToken); |
|
|
|
@ -61,7 +62,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
@@ -61,7 +62,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
|
|
|
|
|
var methods = type.GetMembers(m => m is IMethod, Options).OfType<IMethod>(); |
|
|
|
|
foreach (var method in methods) |
|
|
|
|
{ |
|
|
|
|
if (IsUsedInMethod((IMethod)analyzedSymbol, method, context)) |
|
|
|
|
if (IsUsedInMethod(analyzedMethod, analyzedBaseMethod, method, context)) |
|
|
|
|
{ |
|
|
|
|
mapping ??= context.Language.GetCodeMappingInfo(parentModule.PEFile, type.MetadataToken); |
|
|
|
|
var parent = mapping.GetParentMethod((MethodDefinitionHandle)method.MetadataToken); |
|
|
|
@ -71,12 +72,12 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
@@ -71,12 +72,12 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
|
|
|
|
|
|
|
|
|
|
foreach (var property in type.Properties) |
|
|
|
|
{ |
|
|
|
|
if (property.CanGet && IsUsedInMethod((IMethod)analyzedSymbol, property.Getter, context)) |
|
|
|
|
if (property.CanGet && IsUsedInMethod(analyzedMethod, analyzedBaseMethod, property.Getter, context)) |
|
|
|
|
{ |
|
|
|
|
yield return property; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (property.CanSet && IsUsedInMethod((IMethod)analyzedSymbol, property.Setter, context)) |
|
|
|
|
if (property.CanSet && IsUsedInMethod(analyzedMethod, analyzedBaseMethod, property.Setter, context)) |
|
|
|
|
{ |
|
|
|
|
yield return property; |
|
|
|
|
continue; |
|
|
|
@ -85,17 +86,17 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
@@ -85,17 +86,17 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
|
|
|
|
|
|
|
|
|
|
foreach (var @event in type.Events) |
|
|
|
|
{ |
|
|
|
|
if (@event.CanAdd && IsUsedInMethod((IMethod)analyzedSymbol, @event.AddAccessor, context)) |
|
|
|
|
if (@event.CanAdd && IsUsedInMethod(analyzedMethod, analyzedBaseMethod, @event.AddAccessor, context)) |
|
|
|
|
{ |
|
|
|
|
yield return @event; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (@event.CanRemove && IsUsedInMethod((IMethod)analyzedSymbol, @event.RemoveAccessor, context)) |
|
|
|
|
if (@event.CanRemove && IsUsedInMethod(analyzedMethod, analyzedBaseMethod, @event.RemoveAccessor, context)) |
|
|
|
|
{ |
|
|
|
|
yield return @event; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (@event.CanInvoke && IsUsedInMethod((IMethod)analyzedSymbol, @event.InvokeAccessor, context)) |
|
|
|
|
if (@event.CanInvoke && IsUsedInMethod(analyzedMethod, analyzedBaseMethod, @event.InvokeAccessor, context)) |
|
|
|
|
{ |
|
|
|
|
yield return @event; |
|
|
|
|
continue; |
|
|
|
@ -104,12 +105,12 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
@@ -104,12 +105,12 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool IsUsedInMethod(IMethod analyzedEntity, IMethod method, AnalyzerContext context) |
|
|
|
|
bool IsUsedInMethod(IMethod analyzedEntity, IMethod analyzedBaseMethod, IMethod method, AnalyzerContext context) |
|
|
|
|
{ |
|
|
|
|
return ScanMethodBody(analyzedEntity, method, context.GetMethodBody(method)); |
|
|
|
|
return ScanMethodBody(analyzedEntity, method, analyzedBaseMethod, context.GetMethodBody(method)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool ScanMethodBody(IMethod analyzedMethod, IMethod method, MethodBodyBlock methodBody) |
|
|
|
|
static bool ScanMethodBody(IMethod analyzedMethod, IMethod method, IMethod analyzedBaseMethod, MethodBodyBlock methodBody) |
|
|
|
|
{ |
|
|
|
|
if (methodBody == null) |
|
|
|
|
return false; |
|
|
|
@ -117,7 +118,6 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
@@ -117,7 +118,6 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
|
|
|
|
|
var mainModule = (MetadataModule)method.ParentModule; |
|
|
|
|
var blob = methodBody.GetILReader(); |
|
|
|
|
|
|
|
|
|
var baseMethod = (IMethod)InheritanceHelper.GetBaseMember(analyzedMethod); |
|
|
|
|
var genericContext = new Decompiler.TypeSystem.GenericContext(); // type parameters don't matter for this analyzer
|
|
|
|
|
|
|
|
|
|
while (blob.RemainingBytes > 0) |
|
|
|
@ -139,7 +139,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
@@ -139,7 +139,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
|
|
|
|
|
var member = MetadataTokenHelpers.EntityHandleOrNil(blob.ReadInt32()); |
|
|
|
|
if (!AnalyzerHelpers.IsPossibleReferenceTo(member, mainModule.PEFile, analyzedMethod)) |
|
|
|
|
{ |
|
|
|
|
if (baseMethod == null || !AnalyzerHelpers.IsPossibleReferenceTo(member, mainModule.PEFile, baseMethod)) |
|
|
|
|
if (analyzedBaseMethod == null || !AnalyzerHelpers.IsPossibleReferenceTo(member, mainModule.PEFile, analyzedBaseMethod)) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
@ -157,9 +157,9 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
@@ -157,9 +157,9 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
|
|
|
|
|
if (m == null) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
if (opCode == ILOpCode.Callvirt && baseMethod != null) |
|
|
|
|
if (opCode == ILOpCode.Callvirt && analyzedBaseMethod != null) |
|
|
|
|
{ |
|
|
|
|
if (IsSameMember(baseMethod, m)) |
|
|
|
|
if (IsSameMember(analyzedBaseMethod, m)) |
|
|
|
|
{ |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|