Browse Source

Fix #2653: ILSpy reports wrong visibility for overridden protected internal properties if located in another assembly.

pull/2679/head
Siegfried Pammer 4 years ago
parent
commit
a121e7c6ca
  1. 17
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataProperty.cs

17
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataProperty.cs

@ -233,10 +233,25 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -233,10 +233,25 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
{
if (IsOverride && (getter == null || setter == null))
{
// Overrides may change the accessibility of property accessors, hence calculating the accessibility from
// the accessors is not sufficient. We need to "copy" accessibility from the baseMember.
foreach (var baseMember in InheritanceHelper.GetBaseMembers(this, includeImplementedInterfaces: false))
{
if (!baseMember.IsOverride)
return baseMember.Accessibility;
{
// See https://github.com/icsharpcode/ILSpy/issues/2653
// "protected internal" (ProtectedOrInternal) accessibility is "reduced"
// to "protected" accessibility across assembly boundaries.
if (baseMember.Accessibility == Accessibility.ProtectedOrInternal
&& this.ParentModule?.PEFile != baseMember.ParentModule?.PEFile)
{
return Accessibility.Protected;
}
else
{
return baseMember.Accessibility;
}
}
}
}
return AccessibilityExtensions.Union(

Loading…
Cancel
Save