-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Handle file-scoped namespaces in Logging Source Generator #57894
Handle file-scoped namespaces in Logging Source Generator #57894
Conversation
Handle namespace not being emitted when file-scoped namespaces are used for a log class. Relates to dotnet#57880.
Tagging subscribers to this area: @maryamariyan Issue DetailsHandle namespace not being emitted when file-scoped namespaces are used for a log class. Relates to #57880.
|
...ns/tests/Microsoft.Extensions.Logging.Generators.Tests/LoggerMessageGeneratorEmitterTests.cs
Show resolved
Hide resolved
Now that #57088 has been merged into |
@chsienki is there a more general way we could use to find the namespace (via the semantic model) rather than using |
Also note we should test (and possibly fix) the System.Text.Json source generator for the same scenario. |
Anything more I need to do with this PR for merge? |
confirmed with @sharwell offline that using |
@martincostello would you be interested in taking a look at the Json source generator side as well for file-scoped namespaces either in this or in a separate PR? |
Does this need porting? Would we otherwise be broken as soon as someone enables "automatic usings"? |
Sure, I'll take a look at some point this weekend. |
Yeah I think it would make sense to port this to the 6.0 branch, if someone with permissions could do the honours? |
@maryamariyan Just created a quick console app to check out the JSON stuff with file-scoped namespaces and seems fine using version > dotnet build
Microsoft (R) Build Engine version 17.0.0-preview-21453-03+74e9935a4 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
JsonSourceGenerator -> C:\Coding\martincostello\JsonSourceGenerator\bin\Debug\net6.0\JsonSourceGenerator.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.86 > dotnet run
{"FirstName":"Jane","LastName":"Doe"}
|
The reason Json works is because it is using runtime/src/libraries/System.Text.Json/gen/Reflection/TypeWrapper.cs Lines 175 to 178 in 0becd27
Maybe we should consider doing something similar in the Logging generator? |
will take a look |
Handle namespace not being emitted when file-scoped namespaces are used for a log class. Relates to dotnet#57880.
Does JSON need a test to protect this scenario? |
Handle namespace not being emitted when file-scoped namespaces are used for a log class.
Relates to #57880.