This is an automated email from the ASF dual-hosted git repository.

blankensteiner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-dotpulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 7428797  TryParse improvements (#172)
7428797 is described below

commit 7428797b7b22774c661683f3ac2cc21347d9cf11
Author: entvex <[email protected]>
AuthorDate: Mon Aug 28 10:39:45 2023 +0200

    TryParse improvements (#172)
    
    TryParse didn't guard for null or whitespace
    Added missing feature in CHANGELOG.md
    Improved code doc for TryParse
    
    Co-authored-by: David Jensen <[email protected]>
---
 CHANGELOG.md               |  1 +
 src/DotPulsar/MessageId.cs | 12 ++++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 69cc145..37274b2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ The format is based on [Keep a 
Changelog](https://keepachangelog.com/en/1.1.0/)
 
 - Added partitioned topic support for the Consumer and Reader (was already 
implemented for the Producer)
 - MessageId now includes an extra field for the topic
+- A TryParse method is added to MessageId. Therefore, it is now possible to 
parse a string into a MessageId object
 - Support for `ProducerAccessMode` to prevent multiple producers on a single 
topic
 - A new `Fenced` state for producers which is a final state
 - The ability to explicitly set compression information on an outgoing message 
using `MessageMetadata` (for sending pre-compressed messages)
diff --git a/src/DotPulsar/MessageId.cs b/src/DotPulsar/MessageId.cs
index c236015..f32a8d6 100644
--- a/src/DotPulsar/MessageId.cs
+++ b/src/DotPulsar/MessageId.cs
@@ -153,12 +153,20 @@ public sealed class MessageId : IEquatable<MessageId>, 
IComparable<MessageId>
     }
 
     /// <summary>
-    /// Converts a string into a MessageId
+    /// Converts the string representation of a message id to its object 
equivalent. A return value indicates whether the conversion succeeded.
     /// </summary>
-    /// <returns>True is successfull and false if not</returns>
+    /// <param name="s">A string containing a message id to convert.</param>
+    /// <param name="result">
+    /// When this method returns, contains the MessageId equivalent of the 
string contained in s, if the conversion succeeded, or MessageId.Earliest if 
the conversion failed.
+    /// The conversion fails if the s parameter is null or Empty, or is not of 
the correct format.
+    /// This parameter is passed uninitialized; any value originally supplied 
in result will be overwritten.
+    /// </param>
+    /// <returns> true if the string was converted successfully; otherwise, 
false. </returns>
     public static bool TryParse(string s, out MessageId result)
     {
         result = Earliest;
+        if (string.IsNullOrWhiteSpace(s))
+            return false;
         var input = s.AsMemory();
         var startOfNextEntry = 0;
         var index = 0;

Reply via email to