#if NET_4_0 || MOONLIGHT || MOBILE
public static Guid Parse (string input)
{
+ if (input == null)
+ throw new ArgumentNullException ("input");
+
Guid guid;
if (!TryParse (input, out guid))
throw CreateFormatException (input);
public static Guid ParseExact (string input, string format)
{
+ if (input == null)
+ throw new ArgumentNullException ("input");
+ if (format == null)
+ throw new ArgumentNullException ("format");
+
Guid guid;
if (!TryParseExact (input, format, out guid))
throw CreateFormatException (input);
public static bool TryParse (string input, out Guid result)
{
- if (input == null)
- throw new ArgumentNullException ("input");
+ if (input == null) {
+ result = Empty;
+ return false;
+ }
var parser = new GuidParser (input);
return parser.Parse (out result);
public static bool TryParseExact (string input, string format, out Guid result)
{
- if (input == null)
- throw new ArgumentNullException ("input");
- if (format == null)
- throw new ArgumentNullException ("format");
+ if (input == null || format == null) {
+ result = Empty;
+ return false;
+ }
var parser = new GuidParser (input);
return parser.Parse (ParseFormat (format), out result);
{
Guid.ParseExact ("{0x00010203,0x0405,0x0607,{0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}}", "D");
}
+
+ [Test]
+ public void TryParse()
+ {
+ Guid guid;
+ Assert.IsFalse (Guid.TryParse(null, out guid), "A1");
+ Assert.AreEqual (Guid.Empty, guid, "A2");
+ Assert.IsFalse (Guid.TryParse("", out guid), "A3");
+ Assert.AreEqual (Guid.Empty, guid, "A4");
+ Assert.IsFalse (Guid.TryParse("foobar", out guid), "A5");
+ Assert.AreEqual (Guid.Empty, guid, "A6");
+ }
+
+ [Test]
+ public void TryParseExact()
+ {
+ Guid guid;
+ Assert.IsFalse (Guid.TryParseExact(null, null, out guid), "A1");
+ Assert.AreEqual (Guid.Empty, guid, "A2");
+ Assert.IsFalse (Guid.TryParseExact("", null, out guid), "A3");
+ Assert.AreEqual (Guid.Empty, guid, "A4");
+ Assert.IsFalse (Guid.TryParseExact("foobar", null, out guid), "A5");
+ Assert.AreEqual (Guid.Empty, guid, "A6");
+ }
#endif
}
}