Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Refactor ConditionBasedFilter when-filter to use ternary operator - #5281

#5281
Merged
snakefoot merged 2 commits into
NLog:devNLog/NLog:devfrom
jokoyoski:FilterResultCheckRefactoringjokoyoski/NLog:FilterResultCheckRefactoringCopy head branch name to clipboard
Jul 12, 2023
Merged

Refactor ConditionBasedFilter when-filter to use ternary operator#5281
snakefoot merged 2 commits into
NLog:devNLog/NLog:devfrom
jokoyoski:FilterResultCheckRefactoringjokoyoski/NLog:FilterResultCheckRefactoringCopy head branch name to clipboard

Conversation

@jokoyoski

Copy link
Copy Markdown
Contributor

In the refactored code, we directly compare the result of Condition.Evaluate(logEvent) with ConditionExpression.BoxedTrue to determine if the condition is true. Instead of assigning the result to val, we directly use the comparison result to determine the path of execution. This simplifies the code by removing the need for the if statement and condenses it into a single return statement.

@welcome

welcome Bot commented Jul 10, 2023

Copy link
Copy Markdown

Thanks for opening this pull request!
We will try to review this soon! Please note that pull requests with unit tests are earlier accepted 👼

}

return FilterDefaultAction;
bool isConditionTrue = Condition.Evaluate(logEvent) == ConditionExpression.BoxedTrue;

@snakefoot snakefoot Jul 11, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can it become:

            object val = Condition.Evaluate(logEvent);
            return ConditionExpression.BoxedTrue.Equals(val) ? Action : FilterDefaultAction;

I like that ConditionExpression.BoxedTrue.Equals(val) avoids an additional null-check, and also limits the equals-operation to only boolean-comparison. I also like not having too many expressions in a single statement.

@snakefoot

Copy link
Copy Markdown
Contributor

Have now fixed the Azure DevOps-pipeline with #5282, so if you rebase to dev-branch then they should become green.

@jokoyoski

Copy link
Copy Markdown
Contributor Author

Okay will do that and made the update you advice. Thanks

@jokoyoski

Copy link
Copy Markdown
Contributor Author

@snakefoot please check

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@snakefoot snakefoot changed the title reafctored the filter result check method Refactor ConditionBasedFilter when filter to use ternary operator Jul 12, 2023

@snakefoot snakefoot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good

@snakefoot
snakefoot merged commit 0ccf9db into NLog:dev Jul 12, 2023
@welcome

welcome Bot commented Jul 12, 2023

Copy link
Copy Markdown

Hooray your first pull request is merged! Thanks for the contribution! Looking for more? 👼 Please check the up-for-grabs issues - thanks!
thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.