\r
\r
using System;\r
+using System.Globalization;\r
using System.Net.Sockets;\r
using System.Runtime.InteropServices;\r
using System.Text;\r
\r
return slot;\r
}\r
+\r
+ static bool TryParse (string prefix, out int res)\r
+ {\r
+#if NET_2_0\r
+ return Int32.TryParse (prefix, NumberStyles.Integer, CultureInfo.InvariantCulture, out res);\r
+#else\r
+ try {\r
+ res = Int32.Parse (prefix, NumberStyles.Integer, CultureInfo.InvariantCulture);\r
+ } catch (Exception) {\r
+ res = -1;\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+#endif\r
+ }\r
\r
public static bool TryParse (string ipString, out IPv6Address result)\r
{\r
int pos = ipString.LastIndexOf ('/');\r
if (pos != -1) {\r
string prefix = ipString.Substring (pos + 1);\r
- try {\r
- prefixLen = Int32.Parse (prefix);\r
- } catch (Exception) {\r
+ if (!TryParse (prefix , out prefixLen))\r
prefixLen = -1;\r
- }\r
if (prefixLen < 0 || prefixLen > 128)\r
return false;\r
ipString = ipString.Substring (0, pos);\r
pos = ipString.LastIndexOf ('%');\r
if (pos != -1) {\r
string prefix = ipString.Substring (pos + 1);\r
- try {\r
- scopeId = Int32.Parse (prefix);\r
- } \r
- catch (Exception) {\r
+ if (!TryParse (prefix, out scopeId))\r
scopeId = 0;\r
- }\r
ipString = ipString.Substring (0, pos);\r
} \r
}\r
// Is there an ipv4 address at the end?\r
//\r
bool ipv4 = false;\r
- int pos2 = ipString.LastIndexOf (":");\r
+ int pos2 = ipString.LastIndexOf (':');\r
if (pos2 == -1)\r
return false;\r
\r