Skip to content

Commit f9da13c

Browse files
committed
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....
1 parent 2e0fcee commit f9da13c

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

ICSharpCode.Decompiler/Ast/TypesHierarchyHelpers.cs

+19-15
Original file line numberDiff line numberDiff line change
@@ -185,24 +185,28 @@ public static bool IsVisibleFromDerived(IMemberDefinition baseMember, TypeDefini
185185
if (derivedType == null)
186186
throw new ArgumentNullException("derivedType");
187187

188-
var visibility = IsVisibleFromDerived(baseMember);
189-
if (visibility.HasValue)
190-
return visibility.Value;
191-
192-
if (baseMember.DeclaringType.Module == derivedType.Module)
193-
return true;
194-
// TODO: Check also InternalsVisibleToAttribute.
188+
MethodAttributes attrs = GetAccessAttributes(baseMember) & MethodAttributes.MemberAccessMask;
189+
if (attrs == MethodAttributes.Private)
195190
return false;
196-
}
197191

198-
private static bool? IsVisibleFromDerived(IMemberDefinition member)
199-
{
200-
MethodAttributes attrs = GetAccessAttributes(member) & MethodAttributes.MemberAccessMask;
201-
if (attrs == MethodAttributes.Private)
192+
if (attrs == MethodAttributes.Assembly || attrs == MethodAttributes.FamANDAssem) {
193+
var derivedTypeAsm = derivedType.Module.Assembly;
194+
var asm = baseMember.DeclaringType.Module.Assembly;
195+
if (asm.HasCustomAttributes) {
196+
var attributes = asm.CustomAttributes
197+
.Where(attr => attr.AttributeType.FullName == "System.Runtime.CompilerServices.InternalsVisibleToAttribute");
198+
foreach (var attribute in attributes) {
199+
string assemblyName = attribute.ConstructorArguments[0].Value as string;
200+
assemblyName = assemblyName.Split(',')[0]; // strip off any public key info
201+
if (assemblyName == derivedTypeAsm.Name.Name)
202+
return true;
203+
}
204+
}
202205
return false;
203-
if (attrs == MethodAttributes.Assembly || attrs == MethodAttributes.FamANDAssem)
204-
return null;
205-
return true;
206+
}
207+
208+
return true;
209+
206210
}
207211

208212
private static MethodAttributes GetAccessAttributes(IMemberDefinition member)

0 commit comments

Comments
 (0)