Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObsoleteAttribute inheritance #18

Closed
amoraller opened this issue Nov 14, 2023 · 3 comments
Closed

ObsoleteAttribute inheritance #18

amoraller opened this issue Nov 14, 2023 · 3 comments

Comments

@amoraller
Copy link

Nice source generator. Thanks.

If i want delegate implementation to interface with Obsolete methods, i have compilation warnings CS0618.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0618?f1url=%3FappId%3Droslyn%26k%3Dk(CS0618)

For example, i want delegate Nlog.ILogger implmentation.

NLog source coge:

    /// <summary>
    /// Writes the diagnostic message at the <c>Debug</c> level using the specified parameters.
    /// </summary>
    /// <param name="message">A <see langword="string" /> containing format items.</param>
    /// <param name="args">Arguments to format.</param>
    [MessageTemplateFormatMethod("message")]
    void Debug([Localizable(false)][StructuredMessageTemplate] string message, params object[] args);

    /// <summary>
    /// Writes the diagnostic message and exception at the <c>Debug</c> level.
    /// </summary>
    /// <param name="message">A <see langword="string" /> to be written.</param>
    /// <param name="exception">An exception to be logged.</param>
    /// <remarks>This method was marked as obsolete before NLog 4.3.11 and it may be removed in a future release.</remarks>
    [Obsolete("Use Debug(Exception exception, string message) method instead. Marked obsolete with v4.3.11")]
    [EditorBrowsable(EditorBrowsableState.Never)]
    void Debug([Localizable(false)] string message, Exception exception);

 
    /// <summary>

Generated code:

    void NLog.ILogger.Debug(string message, params object[] args) => this._nlogImpl.Debug(message, args);

    void NLog.ILogger.Debug(string message, System.Exception exception) => this._nlogImpl.Debug(message, exception);

image

I think, we want nesting Obsolete attribute.

@beakona
Copy link
Owner

beakona commented Nov 14, 2023

As I understood the real cause of the problem, the ObsoleteAttribute has Inherited=false and a copy of that attribute should be added to the generated source so compiler would not generate warning.
It seems the correct aproach would be to add an additional attribute PassthroughAttributes="Obsolete" (that is the list of attributes). In that case Obsolete would be forwarded by default, but anyone could change that behaviour for other attributes.

I don't have enough free time at the moment and will try to solve this and another issue by the end of this year.

beakona added a commit that referenced this issue Nov 28, 2023
@beakona
Copy link
Owner

beakona commented Nov 29, 2023

I've made nuget prerelease package 1.0.30-pre that should fix this issue.

@amoraller
Copy link
Author

thanks. It work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants