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/02 20:03:03 UTC
[qpid-proton-dotnet] branch main updated: PROTON-2721 Add implicit conversions for Symbol 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 c8f7082 PROTON-2721 Add implicit conversions for Symbol types
c8f7082 is described below
commit c8f7082ed7dc3d09b93c5faef0f7b9d8fe4cc620
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Tue May 2 16:02:03 2023 -0400
PROTON-2721 Add implicit conversions for Symbol types
Allow for implicit conversion to string or from string when working
with Symbol types
---
src/Proton/Types/Symbol.cs | 12 +++++++++
test/Proton.Tests/Types/SymbolTest.cs | 50 +++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff --git a/src/Proton/Types/Symbol.cs b/src/Proton/Types/Symbol.cs
index fdd980d..9d3acc7 100644
--- a/src/Proton/Types/Symbol.cs
+++ b/src/Proton/Types/Symbol.cs
@@ -52,6 +52,18 @@ namespace Apache.Qpid.Proton.Types
hashCode = buffer.GetHashCode();
}
+ /// <summary>
+ /// Allows a string value to be implicitly converted to a Symbol
+ /// </summary>
+ /// <param name="symbolString">The String to convert</param>
+ public static implicit operator Symbol(string symbolString) => Lookup(symbolString);
+
+ /// <summary>
+ /// Allows a Symbol object to be implicitly converted to a string value.
+ /// </summary>
+ /// <param name="value">The Symbol to convert</param>
+ public static implicit operator string(Symbol value) => value?.ToString();
+
/// <summary>
/// Lookup or create a singleton instance of the given Symbol that has the
/// matching name to the string value provided.
diff --git a/test/Proton.Tests/Types/SymbolTest.cs b/test/Proton.Tests/Types/SymbolTest.cs
index 49dae36..89adcc7 100644
--- a/test/Proton.Tests/Types/SymbolTest.cs
+++ b/test/Proton.Tests/Types/SymbolTest.cs
@@ -226,5 +226,55 @@ namespace Apache.Qpid.Proton.Types
Assert.AreNotSame(symbol1, symbol2);
Assert.AreNotSame(symbol1.ToString(), symbol2.ToString());
}
+
+ [Test]
+ public void TestImplicitToStringHandlesNull()
+ {
+ string symbolString = null;
+
+ Symbol symbol1 = (Symbol)symbolString;
+
+ Assert.IsNull(symbol1);
+ }
+
+ [Test]
+ public void TestImplicitToSymbolHandlesNull()
+ {
+ Symbol symbol = null;
+
+ string symString = (string)symbol;
+
+ Assert.IsNull(symString);
+ }
+
+ [Test]
+ public void TestImplicitToSymbolProducesSingleton()
+ {
+ string symbolString = "Symbol-string";
+
+ Symbol symbol1 = (Symbol)symbolString;
+ Symbol symbol2 = (Symbol)symbolString;
+
+ Assert.AreEqual(symbolString, symbol1.ToString());
+ Assert.AreEqual(symbolString, symbol2.ToString());
+
+ Assert.AreSame(symbol1, symbol2);
+ Assert.AreSame(symbol1.ToString(), symbol2.ToString());
+ }
+
+ [Test]
+ public void TestImplicitToStringProducesSingleton()
+ {
+ string symbolString = "Symbol-string";
+
+ Symbol symbol1 = (Symbol)symbolString;
+ Symbol symbol2 = (Symbol)symbolString;
+
+ Assert.AreEqual(symbolString, (string)symbol1);
+ Assert.AreEqual(symbolString, (string)symbol2);
+
+ Assert.AreSame(symbol1, symbol2);
+ Assert.AreSame((string)symbol1, (string)symbol2);
+ }
}
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org