Sfoglia il codice sorgente

Use switch instead of if/elseif.

Gert Driesen 7 anni fa
parent
commit
cfd412529e
1 ha cambiato i file con 11 aggiunte e 12 eliminazioni
  1. 11 12
      src/Renci.SshNet/Session.cs

+ 11 - 12
src/Renci.SshNet/Session.cs

@@ -2287,19 +2287,18 @@ namespace Renci.SshNet
 
             byte[] address;
 
-            if (ip.AddressFamily == AddressFamily.InterNetwork)
+            switch (ip.AddressFamily)
             {
-                addressType = 0x01; // IPv4
-                address = ip.GetAddressBytes();
-            }
-            else if (ip.AddressFamily == AddressFamily.InterNetworkV6)
-            {
-                addressType = 0x04; // IPv6
-                address = ip.GetAddressBytes();
-            }
-            else
-            {
-                throw new ProxyException(string.Format("SOCKS5: IP address '{0}' is not supported.", ip));
+                case AddressFamily.InterNetwork:
+                    addressType = 0x01; // IPv4
+                    address = ip.GetAddressBytes();
+                    break;
+                case AddressFamily.InterNetworkV6:
+                    addressType = 0x04; // IPv6
+                    address = ip.GetAddressBytes();
+                    break;
+                default:
+                    throw new ProxyException(string.Format("SOCKS5: IP address '{0}' is not supported.", ip));
             }
 
             return address;