Skip to content

Commit

Permalink
Merge pull request #66 from jonorossi/fix-protected-internal
Browse files Browse the repository at this point in the history
Output protected internal access modifier as protected
  • Loading branch information
danielmarbach authored Jul 17, 2019
2 parents 56aa60b + 99cf82f commit 8622307
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/PublicApiGenerator/ApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,16 +620,12 @@ static object FormatParameterConstant(IConstantProvider parameter)
static MemberAttributes GetMethodAttributes(MethodDefinition method)
{
MemberAttributes access = 0;
if (method.IsFamily)
if (method.IsFamily || method.IsFamilyOrAssembly)
access = MemberAttributes.Family;
if (method.IsPublic)
access = MemberAttributes.Public;
if (method.IsAssembly)
access = MemberAttributes.Assembly;
if (method.IsFamilyAndAssembly)
access = MemberAttributes.FamilyAndAssembly;
if (method.IsFamilyOrAssembly)
access = MemberAttributes.FamilyOrAssembly;

MemberAttributes scope = 0;
if (method.IsStatic)
Expand Down Expand Up @@ -764,7 +760,8 @@ static MemberAttributes GetPropertyAttributes(MemberAttributes getterAttributes,
static bool HasVisiblePropertyMethod(MemberAttributes attributes)
{
var access = attributes & MemberAttributes.AccessMask;
return access == MemberAttributes.Public || access == MemberAttributes.Family ||
return access == MemberAttributes.Public ||
access == MemberAttributes.Family ||
access == MemberAttributes.FamilyOrAssembly;
}

Expand All @@ -789,7 +786,7 @@ static void AddFieldToTypeDeclaration(CodeTypeDeclaration typeDeclaration, Field
MemberAttributes attributes = 0;
if (memberInfo.HasConstant)
attributes |= MemberAttributes.Const;
if (memberInfo.IsFamily)
if (memberInfo.IsFamily || memberInfo.IsFamilyOrAssembly)
attributes |= MemberAttributes.Family;
if (memberInfo.IsPublic)
attributes |= MemberAttributes.Public;
Expand Down
2 changes: 2 additions & 0 deletions src/PublicApiGeneratorTests/Field_visibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public void Only_public_and_protected_fields_visible()
public class ClassWithFields
{
protected int protectedFieldIsVisible;
protected int protectedInternalFieldIsVisible;
public int publicFieldIsVisible;
public ClassWithFields() { }
}
Expand All @@ -35,6 +36,7 @@ public class ClassWithFields
internal int internalFieldNotVisible;

protected int protectedFieldIsVisible;
protected internal int protectedInternalFieldIsVisible;
public int publicFieldIsVisible;
}
}
Expand Down
23 changes: 22 additions & 1 deletion src/PublicApiGeneratorTests/Method_visibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ public ClassWithInternalMethod() { }
}");
}

[Fact]
public void Should_show_protected_internal_methods()
{
AssertPublicApi<ClassWithProtectedInternalMethod>(
@"namespace PublicApiGeneratorTests.Examples
{
public class ClassWithProtectedInternalMethod
{
public ClassWithProtectedInternalMethod() { }
protected void DoSomething() { }
}
}");
}

[Fact]
public void Should_not_show_private_methods()
{
Expand Down Expand Up @@ -86,9 +100,16 @@ internal void DoSomething()
}
}

public class ClassWithProtectedInternalMethod
{
protected internal void DoSomething()
{
}
}

public class ClassWithPrivateMethod
{
private void Method()
private void DoSomething()
{
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/PublicApiGeneratorTests/Property_visibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Should_output_protected_internal_property()
public class ClassWithProtectedInternalProperty
{
public ClassWithProtectedInternalProperty() { }
protected internal string Value { get; set; }
protected string Value { get; set; }
}
}");
}
Expand Down Expand Up @@ -244,7 +244,7 @@ public void Should_output_protected_internal_getter_for_public_property_with_cor
public class ClassWithProtectedInternalGetterPublicSetter
{
public ClassWithProtectedInternalGetterPublicSetter() { }
public string Value1 { protected internal get; set; }
public string Value1 { protected get; set; }
}
}");
}
Expand Down

0 comments on commit 8622307

Please sign in to comment.