Browse Source

fix #537: ILSpy can't find any Overridden By methods

Overriding methods were not shown because the base method was marked
'internal' and so would normally only be visible within its own
assembly.
However the assembly had a InternalsVisibleToAttribute specified which
allowed access from the assembly containing the derived types....
pull/539/head
Ed Harvey 11 years ago
parent
commit
f9da13cbc0
  1. 28
      ICSharpCode.Decompiler/Ast/TypesHierarchyHelpers.cs

28
ICSharpCode.Decompiler/Ast/TypesHierarchyHelpers.cs

@ -185,24 +185,28 @@ namespace ICSharpCode.Decompiler.Ast
if (derivedType == null) if (derivedType == null)
throw new ArgumentNullException("derivedType"); throw new ArgumentNullException("derivedType");
var visibility = IsVisibleFromDerived(baseMember); MethodAttributes attrs = GetAccessAttributes(baseMember) & MethodAttributes.MemberAccessMask;
if (visibility.HasValue) if (attrs == MethodAttributes.Private)
return visibility.Value; return false;
if (baseMember.DeclaringType.Module == derivedType.Module) if (attrs == MethodAttributes.Assembly || attrs == MethodAttributes.FamANDAssem) {
var derivedTypeAsm = derivedType.Module.Assembly;
var asm = baseMember.DeclaringType.Module.Assembly;
if (asm.HasCustomAttributes) {
var attributes = asm.CustomAttributes
.Where(attr => attr.AttributeType.FullName == "System.Runtime.CompilerServices.InternalsVisibleToAttribute");
foreach (var attribute in attributes) {
string assemblyName = attribute.ConstructorArguments[0].Value as string;
assemblyName = assemblyName.Split(',')[0]; // strip off any public key info
if (assemblyName == derivedTypeAsm.Name.Name)
return true; return true;
// TODO: Check also InternalsVisibleToAttribute. }
}
return false; return false;
} }
private static bool? IsVisibleFromDerived(IMemberDefinition member)
{
MethodAttributes attrs = GetAccessAttributes(member) & MethodAttributes.MemberAccessMask;
if (attrs == MethodAttributes.Private)
return false;
if (attrs == MethodAttributes.Assembly || attrs == MethodAttributes.FamANDAssem)
return null;
return true; return true;
} }
private static MethodAttributes GetAccessAttributes(IMemberDefinition member) private static MethodAttributes GetAccessAttributes(IMemberDefinition member)

Loading…
Cancel
Save