-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Conversation
Tagging subscribers to this area: @maryamariyan Issue DetailsFixes: #52277
|
@@ -115,7 +120,7 @@ public IReadOnlyList<LoggerClass> GetLogClasses(IEnumerable<ClassDeclarationSynt | |||
Name = methodSymbol.Name, | |||
Level = level, | |||
Message = message, | |||
EventId = eventId, | |||
EventId = (int)eventId.Value, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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;
?
Closing this PR, addressing this fix in another one. |
Fixes: #52277