codecentric / net_automatic_interface

.Net Source Generator for Automatic Interfaces
MIT License
62 stars 14 forks source link

Interfaces generated for classes with `override` or `new` methods contain duplicates #50

Closed simonmckenzie closed 3 months ago

simonmckenzie commented 5 months ago

The current code will insert multiple definitions of a method when that method has been overridden or shadowed via new.

For example, given these two classes:

public class BaseClass
{
    public virtual bool AMethod();
}

[GenerateAutomaticInterface]
public class DemoClass : BaseClass
{
    public override bool AMethod() => return true;
}

The generated interface will look like this:

[GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
    /// <inheritdoc />
    bool AMethod();

    /// <inheritdoc />
    bool AMethod();
}
simonmckenzie commented 3 months ago

Resolved by the merge of #51

FinnAngelo commented 3 months ago

Hi all FYI: it doesn't look like the fix is sticking - the error is still showing with this;

<PackageReference Include="AutomaticInterface" Version="2.5.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
file class GenerateAutomaticInterface : Attribute;

[GenerateAutomaticInterface]
file class MyButton : System.Windows.Forms.Button;

// OR
[GenerateAutomaticInterface]
file class MyButton : System.Windows.Forms.Button
{
    // This gives **2** instances of the error
    public new event System.EventHandler? ImeModeChanged;
}

I really like the package though - thanks for your work so far!

simonmckenzie commented 3 months ago

HI @FinnAngelo,

My fix was only for methods. It looks like we'll need another issue for events 🤦

Would you be interested in doing this? It'll be much the same as in this PR: https://github.com/codecentric/net_automatic_interface/pull/33

If not, I can have a look later in the week.

FinnAngelo commented 3 months ago

Hi @simonmckenzie - I wont be able to start till this weekend (Sat 10 Aug) but yeah, sure!