daver32 / InterfaceGenerator

A simple source generator that creates interfaces by implementations.
MIT License
36 stars 14 forks source link

Feature Request: Support Records #1

Closed andi0b closed 3 years ago

andi0b commented 3 years ago

This library (1.0.5 on net6.0) works perfectly for me, thanks for the great work!

What I stumbled upon using it was, that records are not supported. It may need some fine tuning to properly support them though.

// records don't work at all for now
[InterfaceGenerator.GenerateAutoInterface]
record Record : IRecord
{
    public void Method(){}
}

// I expect it to generate an interface like that:
internal partial interface IRecord
{
    string Property { get; init; }
    void Method();
    void Deconstruct(out string Property);
}
// classes work fine
[InterfaceGenerator.GenerateAutoInterface]
class Class : IClass
{
    public string Property { get; set; }
    public void Method(){}
}

// this generates a proper interface:
internal partial interface IClass
{
    string Property { get; set; }
    void Method();
}
daver32 commented 3 years ago

I've added support for that now, check out the newest version