PropertiesDictionary - Simplify enumerator when mixing property types#6061
PropertiesDictionary - Simplify enumerator when mixing property types#6061
Conversation
WalkthroughReplaces nullable index state with a non-nullable integer sentinel in PropertiesDictionary, simplifying enumerator state/init, MoveNext, Current* accessors and Reset; updates unit test iteration assertions and replaces switch-based traversal with key/value conditional checks. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (2)src/NLog/Internal/PropertiesDictionary.cs (2)
tests/NLog.UnitTests/Internal/PropertiesDictionaryTests.cs (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
tests/NLog.UnitTests/Internal/PropertiesDictionaryTests.cs (1)
418-425: Same unconventional increment pattern as discussed in the previous comment (lines 375-412).
🧹 Nitpick comments (1)
tests/NLog.UnitTests/Internal/PropertiesDictionaryTests.cs (1)
375-412: Consider standard iteration counter for clarity.The test correctly verifies that both dictionary items are visited by using distinct increments (
i += 2andi += 3, totaling 5). While functionally correct, this pattern is unconventional compared to standard iteration counters (i++expectingi == 2).For improved maintainability, consider using either:
- Sequential counters with order-dependent assertions, or
- A
HashSet<object>to track visited keys/values order-independently
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/NLog/Internal/PropertiesDictionary.cs(2 hunks)tests/NLog.UnitTests/Internal/PropertiesDictionaryTests.cs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/NLog/Internal/PropertiesDictionary.cs (1)
src/NLog/MessageTemplates/MessageTemplateParameter.cs (2)
MessageTemplateParameter(105-111)MessageTemplateParameter(120-126)
tests/NLog.UnitTests/Internal/PropertiesDictionaryTests.cs (1)
src/NLog/Internal/PropertiesDictionary.cs (4)
Equals(715-715)Equals(717-725)Equals(739-742)Equals(753-767)
🔇 Additional comments (4)
src/NLog/Internal/PropertiesDictionary.cs (4)
449-456: LGTM! Clean sentinel-based state tracking.The refactor from nullable
int?to non-nullableintwith sentinel values (-1 for message properties pre-start, int.MinValue for event enumerator mode) eliminates nullable overhead while maintaining clear state semantics. This aligns well with the performance goal of the PR.
458-505: LGTM! Unified boundary check simplifies property accessors.The consistent use of
_messagePropertiesIndex >= 0acrossCurrent,CurrentParameter, andCurrentPropertyprovides a clean single-condition check to determine whether to read from the message properties list or delegate to the event enumerator.
509-528: LGTM! MoveNext logic is correct and simplified.The refactored logic cleanly handles two mutually exclusive enumeration modes:
- Message properties mode (index >= -1): Advances through the message properties list until exhausted
- Event enumerator mode (index < -1): Delegates to the event dictionary enumerator
The boundary check at line 513 safely handles null via the null-conditional operator, returning false when the message properties collection is null or empty.
535-539: LGTM! Reset correctly reinitializes state.The Reset method properly restores the enumerator to its initial state using the same sentinel initialization logic as the constructor, ensuring consistent behavior for repeated enumerations.
0418609 to
22dd68c
Compare
|



No longer attempt to guarantee property ordering, when overriding message-template-properties with additional properties.
By default the underlying Dictionary will try to keep the insert ordering to some point.