beakona / AutoInterface

C# interface-to-member source generator
MIT License
73 stars 9 forks source link

Obsolete support #20

Closed fubar-coder closed 5 months ago

fubar-coder commented 5 months ago

Hi,

I get CS0618 (obsolete member) warnings when some of the interface members are marked as [Obsolete].

Example

using System;

public interface ITest
{
    [Obsolete]
    void DoStuff1();
    void DoStuff2();
}

public class MyTest : ITest
{
    [Obsolete]
    public void DoStuff1() => Console.WriteLine("Do stuff 1");
    public void DoStuff2() => Console.WriteLine("Do stuff 2");
}

public class TestWrapper : ITest
{
    [BeaKona.AutoInterface(typeof(ITest))]
    private readonly ITest _test;

    public TestWrapper(ITest test)
    {
        _test  = test;
    }
}

Now I get warnings for the implemented obsolete function DoStuff1.

Expected outcome

The Obsolete attribute (with all its parameters) should be copied to the generated DoStuff1 function, which would avoid the compiler warning.

Workaround

Currently, I implement the obsolete function myself and add the Obsolete attribute to ensure that DoStuff1 doesn't get generated and thus doesn't cause build warnings.

beakona commented 5 months ago

Hi,

there is an issue #18 which was resolved last month. Currently, the working library is only available as a prerelease (1.0.30 and later).. The latest version is 1.0.35-pre.