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

Make Logging Generator handle null input better #52727

Closed

Conversation

maryamariyan
Copy link
Member

Fixes: #52277

@ghost
Copy link

ghost commented May 13, 2021

Tagging subscribers to this area: @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes: #52277

Author: maryamariyan
Assignees: maryamariyan
Labels:

area-Extensions-Logging

Milestone: -

@@ -115,7 +120,7 @@ public IReadOnlyList<LoggerClass> GetLogClasses(IEnumerable<ClassDeclarationSynt
Name = methodSymbol.Name,
Level = level,
Message = message,
EventId = eventId,
EventId = (int)eventId.Value,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a cast to (int) here?

Copy link
Contributor

@Tornhoof Tornhoof May 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more performant way would be to use GetValueOrDefault() instead of Value. It skips the second not null check, which was already done in .HasValue above

{
int eventId = 0;
int? eventId = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be int? eventId = null;?

@maryamariyan maryamariyan marked this pull request as draft June 3, 2021 22:12
@maryamariyan
Copy link
Member Author

Closing this PR, addressing this fix in another one.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logging Source Generator fails with a NullReferenceException
3 participants