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

[API Proposal]: TagProvider but as an interface #5439

Open
alrz opened this issue Sep 21, 2024 · 0 comments
Open

[API Proposal]: TagProvider but as an interface #5439

alrz opened this issue Sep 21, 2024 · 0 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation untriaged

Comments

@alrz
Copy link

alrz commented Sep 21, 2024

Background and motivation

Right now, TagProvider (and LogProperties) are bound to the partial log method for the generator, but the type and the logger are not always available next to each other. Using an interface you can have deconstruction behavior inside some other lib as well.

API Proposal

interface ITagProvider<TSelf> where TSelf : ITagProvider {
    public abstract static void RecordTags(ITagCollector collector, TSelf value);
}

API Usage

[GenerateTagProvider]
partial class SomeObj;

[LoggerMessage(...)]
private static partial void SomeLog<TSelf>(
    this ILogger logger, 
    [LogProperties] ITagProvider<TSelf> obj) where TSelf: ITagProvider<TSelf>;

Alternative Designs

Using an interceptor like dotnet/runtime#102633 could perhaps help here, but that in and by itself won't cover the generic case without some sort of interfacing.

Risks

No response

@alrz alrz added api-suggestion Early API idea and discussion, it is NOT ready for implementation untriaged labels Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation untriaged
Projects
None yet
Development

No branches or pull requests

1 participant