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 10 years ago
parent
commit
f9da13cbc0
  1. 34
      ICSharpCode.Decompiler/Ast/TypesHierarchyHelpers.cs

34
ICSharpCode.Decompiler/Ast/TypesHierarchyHelpers.cs

@ -185,24 +185,28 @@ namespace ICSharpCode.Decompiler.Ast @@ -185,24 +185,28 @@ namespace ICSharpCode.Decompiler.Ast
if (derivedType == null)
throw new ArgumentNullException("derivedType");
var visibility = IsVisibleFromDerived(baseMember);
if (visibility.HasValue)
return visibility.Value;
if (baseMember.DeclaringType.Module == derivedType.Module)
return true;
// TODO: Check also InternalsVisibleToAttribute.
MethodAttributes attrs = GetAccessAttributes(baseMember) & MethodAttributes.MemberAccessMask;
if (attrs == MethodAttributes.Private)
return false;
}
private static bool? IsVisibleFromDerived(IMemberDefinition member)
{
MethodAttributes attrs = GetAccessAttributes(member) & MethodAttributes.MemberAccessMask;
if (attrs == MethodAttributes.Private)
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 false;
if (attrs == MethodAttributes.Assembly || attrs == MethodAttributes.FamANDAssem)
return null;
return true;
}
return true;
}
private static MethodAttributes GetAccessAttributes(IMemberDefinition member)

Loading…
Cancel
Save