Skip to content

Commit f12e876

Browse files
committed
issue #30, erroneous generation of code for protected interface members. Now, code will be generated only for public and internal members. Now code will not be generated for static as well.
1 parent e8463fc commit f12e876

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

AutoInterfaceSample/Program.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#nullable enable
2+
using BeaKona;
23
using System.Diagnostics.CodeAnalysis;
4+
using System.Drawing;
35

46
namespace AutoInterfaceSample.Test
57
{
@@ -11,6 +13,22 @@ public static void Main()
1113
}
1214
}
1315

16+
public interface IB
17+
{
18+
protected Point Point { get; }
19+
int X() => Point.X;
20+
int Y => Point.Y;
21+
static int Count => 1;
22+
int Count2 => 2;
23+
}
24+
25+
partial class C1 : IB
26+
{
27+
[AutoInterface(typeof(IB), AllowMissingMembers = true)] private IB _inner = default!;
28+
29+
System.Drawing.Point IB.Point => Point.Empty;
30+
}
31+
1432
public class MyDb : IDb
1533
{
1634
[AllowNull]

BeaKona.AutoInterfaceGenerator/AutoInterfaceSourceGenerator.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,17 @@ private static bool IsDuckImplementation(ITypeSymbol receiverType, ITypeSymbol i
675675

676676
bool ShouldGenerate(ISymbol member)
677677
{
678+
if (member.IsStatic)
679+
{
680+
return false;
681+
}
682+
683+
if (member.DeclaredAccessibility is not Accessibility.Public and Accessibility.Internal)
684+
{
685+
//ignore members with "protected" modifier and similar
686+
return false;
687+
}
688+
678689
foreach (var reference in references)
679690
{
680691
if (reference.AllowMissingMembers)

0 commit comments

Comments
 (0)