diff --git a/src/MultiAddress.cs b/src/MultiAddress.cs
index a3830cf..bce04d9 100644
--- a/src/MultiAddress.cs
+++ b/src/MultiAddress.cs
@@ -24,7 +24,7 @@ namespace Ipfs
/// A multi address is considered immutablle and value type equality is implemented.
///
///
- ///
+ ///
public class MultiAddress : IEquatable
{
///
@@ -357,7 +357,27 @@ static public implicit operator MultiAddress(string s)
return new MultiAddress(s);
}
-
+ ///
+ /// Try to create a from the specified
+ /// string.
+ ///
+ ///
+ /// The string representation of a multi address, such as "/ip4/1270.0.01/tcp/5001".
+ ///
+ ///
+ /// null if the string cannot be parsed; otherwise a .
+ ///
+ public static MultiAddress TryCreate(string s)
+ {
+ try
+ {
+ return new MultiAddress(s);
+ }
+ catch
+ {
+ return null;
+ }
+ }
}
diff --git a/src/NetworkProtocol.cs b/src/NetworkProtocol.cs
index 28da1c3..9f6372d 100644
--- a/src/NetworkProtocol.cs
+++ b/src/NetworkProtocol.cs
@@ -13,6 +13,9 @@ namespace Ipfs
///
/// Metadata on an IPFS network address protocol.
///
+ ///
+ /// Protocols are defined at .
+ ///
///
public abstract class NetworkProtocol
{
diff --git a/test/MultiAddressTest.cs b/test/MultiAddressTest.cs
index e17dc61..218dea0 100644
--- a/test/MultiAddressTest.cs
+++ b/test/MultiAddressTest.cs
@@ -297,6 +297,16 @@ public void Ipv6ScopeId_Ignored()
Assert.AreEqual(ma2, ma1);
Assert.AreEqual(ma2.ToString(), ma1.ToString());
}
+
+ [TestMethod]
+ public void TryCreate()
+ {
+ Assert.IsNotNull(MultiAddress.TryCreate("/ip4/1.2.3.4/tcp/80"));
+ Assert.IsNull(MultiAddress.TryCreate(null));
+ Assert.IsNull(MultiAddress.TryCreate(" "));
+ Assert.IsNull(MultiAddress.TryCreate("/tcp/alpha")); // bad port
+ Assert.IsNull(MultiAddress.TryCreate("/foobar")); // bad protocol
+ }
}
}