Add TryParse methods to NodeId and ExpandedNodeId#3302
Conversation
|
|
…tests Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
…e consistency Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
|
@copilot Update the change to not use Try/Catch to return true or false. Instead, change the current Parse to use TryParse and still attain current behavior. |
Changed architecture so TryParse contains the parsing logic without throwing exceptions. Parse methods now call TryParse and throw appropriate exceptions on failure. This avoids using try-catch for control flow as requested. All 1643 BuiltInType tests pass. Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
Updated the implementation per your request. TryParse is now the core implementation containing the parsing logic without throwing exceptions. Parse methods call TryParse and throw appropriate exceptions (ArgumentException or ServiceResultException) when parsing fails. Changes in commit 081af02:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3302 +/- ##
==========================================
+ Coverage 57.86% 58.57% +0.71%
==========================================
Files 367 367
Lines 79969 82447 +2478
Branches 13875 14507 +632
==========================================
+ Hits 46274 48295 +2021
- Misses 29490 29840 +350
- Partials 4205 4312 +107 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| errorMessage = null; | ||
| value = Null; | ||
|
|
||
| try |
There was a problem hiding this comment.
@copilot please also rework this try/catch to use a TryParse model instead of creating the ExpandedNodeId with the text to parse and catching any errors.
There was a problem hiding this comment.
Refactored the ExpandedNodeId parsing in commit 38c62d6. The static InternalTryParse method now directly parses the server index, namespace URI, and inner NodeId components without creating an ExpandedNodeId object in a try-catch block.
Also updated the instance InternalParse method to use a new InternalTryParseInstance helper that implements the TryParse pattern. InternalParse now calls this helper and throws appropriate exceptions (ArgumentException or ServiceResultException) based on the error type.
All 1643 BuiltInType tests pass.
…try-catch Reworked the static InternalTryParse method to directly parse ExpandedNodeId components without creating an ExpandedNodeId object and catching exceptions. Also refactored the instance InternalParse method to use a new InternalTryParseInstance helper that implements TryParse pattern, with InternalParse calling it and throwing appropriate exceptions (ArgumentException or ServiceResultException) on failure. All 1643 BuiltInType tests pass. Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
Adding TryParse methods to NodeId and ExpandedNodeId classes
Plan
Summary
Completed all requested changes. TryParse is the core implementation with parsing logic that returns bool without throwing. Parse methods call TryParse internally and throw appropriate exceptions when parsing fails. This eliminates try-catch for control flow in both NodeId and ExpandedNodeId.
The ExpandedNodeId.InternalTryParse now directly parses the components (server index, namespace URI, and inner NodeId) without creating an ExpandedNodeId object in a try-catch block.
All 1643 BuiltInType tests pass successfully.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.