You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2023/05/09 19:30:22 UTC

[qpid-proton-dotnet] branch main updated: PROTON-2730 Improve ToString for AMQP messaging types

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

tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton-dotnet.git


The following commit(s) were added to refs/heads/main by this push:
     new ebd55c3  PROTON-2730 Improve ToString for AMQP messaging types
ebd55c3 is described below

commit ebd55c331b930274d7a2fbc17bb1e194db0d0bd6
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Tue May 9 15:29:24 2023 -0400

    PROTON-2730 Improve ToString for AMQP messaging types
    
    The collection types need to implement a smarter ToString method in
    order to display contents in logging or output.
---
 src/Proton/Types/Messaging/AmqpSequence.cs            | 19 ++++++++++++++++++-
 src/Proton/Types/Messaging/ApplicationProperties.cs   | 18 +++++++++++++++++-
 src/Proton/Types/Messaging/DeliveryAnnotations.cs     | 18 +++++++++++++++++-
 src/Proton/Types/Messaging/Footer.cs                  | 18 +++++++++++++++++-
 src/Proton/Types/Messaging/MessageAnnotations.cs      | 18 +++++++++++++++++-
 .../Types/Messaging/ApplicationPropertiesTest.cs      |  2 +-
 6 files changed, 87 insertions(+), 6 deletions(-)

diff --git a/src/Proton/Types/Messaging/AmqpSequence.cs b/src/Proton/Types/Messaging/AmqpSequence.cs
index 16a52cf..9009d24 100644
--- a/src/Proton/Types/Messaging/AmqpSequence.cs
+++ b/src/Proton/Types/Messaging/AmqpSequence.cs
@@ -16,6 +16,8 @@
  */
 
 using System.Collections;
+using System.Linq;
+using System.Text;
 
 namespace Apache.Qpid.Proton.Types.Messaging
 {
@@ -57,7 +59,22 @@ namespace Apache.Qpid.Proton.Types.Messaging
 
       public override string ToString()
       {
-         return "AmqpSequence{ " + Value + " }";
+         StringBuilder apStr = new();
+
+         apStr.Append("AmqpSequence{ ");
+
+         if (Value != null && Value.Count > 0)
+         {
+            apStr.Append(string.Join(", ", Enumerable.Range(0, Value.Count).Select(i => Value[i]).ToArray()));
+         }
+         else
+         {
+            apStr.Append("<empty>");
+         }
+
+         apStr.Append(" }");
+
+         return apStr.ToString();
       }
 
       public override int GetHashCode()
diff --git a/src/Proton/Types/Messaging/ApplicationProperties.cs b/src/Proton/Types/Messaging/ApplicationProperties.cs
index 2ed93a4..aa3ba17 100644
--- a/src/Proton/Types/Messaging/ApplicationProperties.cs
+++ b/src/Proton/Types/Messaging/ApplicationProperties.cs
@@ -16,6 +16,7 @@
  */
 
 using System.Collections.Generic;
+using System.Text;
 
 namespace Apache.Qpid.Proton.Types.Messaging
 {
@@ -57,7 +58,22 @@ namespace Apache.Qpid.Proton.Types.Messaging
 
       public override string ToString()
       {
-         return "ApplicationProperties{ " + Value + " }";
+         StringBuilder apStr = new();
+
+         apStr.Append("ApplicationProperties{ ");
+
+         if (Value != null && Value.Count > 0)
+         {
+            apStr.Append(string.Join(", ", Value));
+         }
+         else
+         {
+            apStr.Append("<empty>");
+         }
+
+         apStr.Append(" }");
+
+         return apStr.ToString();
       }
 
       public override int GetHashCode()
diff --git a/src/Proton/Types/Messaging/DeliveryAnnotations.cs b/src/Proton/Types/Messaging/DeliveryAnnotations.cs
index 3b364eb..a218b23 100644
--- a/src/Proton/Types/Messaging/DeliveryAnnotations.cs
+++ b/src/Proton/Types/Messaging/DeliveryAnnotations.cs
@@ -16,6 +16,7 @@
  */
 
 using System.Collections.Generic;
+using System.Text;
 
 namespace Apache.Qpid.Proton.Types.Messaging
 {
@@ -57,7 +58,22 @@ namespace Apache.Qpid.Proton.Types.Messaging
 
       public override string ToString()
       {
-         return "DeliveryAnnotations{ " + Value + " }";
+         StringBuilder apStr = new();
+
+         apStr.Append("DeliveryAnnotations{ ");
+
+         if (Value != null && Value.Count > 0)
+         {
+            apStr.Append(string.Join(", ", Value));
+         }
+         else
+         {
+            apStr.Append("<empty>");
+         }
+
+         apStr.Append(" }");
+
+         return apStr.ToString();
       }
 
       public override int GetHashCode()
diff --git a/src/Proton/Types/Messaging/Footer.cs b/src/Proton/Types/Messaging/Footer.cs
index 46ed694..05378ad 100644
--- a/src/Proton/Types/Messaging/Footer.cs
+++ b/src/Proton/Types/Messaging/Footer.cs
@@ -16,6 +16,7 @@
  */
 
 using System.Collections.Generic;
+using System.Text;
 
 namespace Apache.Qpid.Proton.Types.Messaging
 {
@@ -57,7 +58,22 @@ namespace Apache.Qpid.Proton.Types.Messaging
 
       public override string ToString()
       {
-         return "Footer{ " + Value + " }";
+         StringBuilder apStr = new();
+
+         apStr.Append("Footer{ ");
+
+         if (Value != null && Value.Count > 0)
+         {
+            apStr.Append(string.Join(", ", Value));
+         }
+         else
+         {
+            apStr.Append("<empty>");
+         }
+
+         apStr.Append(" }");
+
+         return apStr.ToString();
       }
 
       public override int GetHashCode()
diff --git a/src/Proton/Types/Messaging/MessageAnnotations.cs b/src/Proton/Types/Messaging/MessageAnnotations.cs
index 1badc5c..aa1ba01 100644
--- a/src/Proton/Types/Messaging/MessageAnnotations.cs
+++ b/src/Proton/Types/Messaging/MessageAnnotations.cs
@@ -16,6 +16,7 @@
  */
 
 using System.Collections.Generic;
+using System.Text;
 
 namespace Apache.Qpid.Proton.Types.Messaging
 {
@@ -57,7 +58,22 @@ namespace Apache.Qpid.Proton.Types.Messaging
 
       public override string ToString()
       {
-         return "MessageAnnotations{ " + Value + " }";
+         StringBuilder apStr = new();
+
+         apStr.Append("MessageAnnotations{ ");
+
+         if (Value != null && Value.Count > 0)
+         {
+            apStr.Append(string.Join(", ", Value));
+         }
+         else
+         {
+            apStr.Append("<empty>");
+         }
+
+         apStr.Append(" }");
+
+         return apStr.ToString();
       }
 
       public override int GetHashCode()
diff --git a/test/Proton.Tests/Types/Messaging/ApplicationPropertiesTest.cs b/test/Proton.Tests/Types/Messaging/ApplicationPropertiesTest.cs
index 9af85aa..232cd20 100644
--- a/test/Proton.Tests/Types/Messaging/ApplicationPropertiesTest.cs
+++ b/test/Proton.Tests/Types/Messaging/ApplicationPropertiesTest.cs
@@ -25,7 +25,7 @@ namespace Apache.Qpid.Proton.Types.Messaging
    public class ApplicationPropertiesTest
    {
       [Test]
-      public void TestTostringOnEmptyObject()
+      public void TestToStringOnEmptyObject()
       {
          Assert.IsNotNull(new ApplicationProperties((IDictionary<string, object>)null).ToString());
       }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org