Jelajahi Sumber

Remove usage of Linq.

Gert Driesen 8 tahun lalu
induk
melakukan
37bfb7c0c8

+ 12 - 5
src/Renci.SshNet/PasswordConnectionInfo.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Linq;
 using System.Net;
 using System.Text;
 using Renci.SshNet.Common;
@@ -248,9 +247,13 @@ namespace Renci.SshNet
         public PasswordConnectionInfo(string host, int port, string username, byte[] password, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword)
             : base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new PasswordAuthenticationMethod(username, password))
         {
-            foreach (var authenticationMethod in AuthenticationMethods.OfType<PasswordAuthenticationMethod>())
+            foreach (var authenticationMethod in AuthenticationMethods)
             {
-                authenticationMethod.PasswordExpired += AuthenticationMethod_PasswordExpired;
+                var pwdAuthentication = authenticationMethod as PasswordAuthenticationMethod;
+                if (pwdAuthentication != null)
+                {
+                    pwdAuthentication.PasswordExpired += AuthenticationMethod_PasswordExpired;
+                }
             }
         }
 
@@ -288,9 +291,13 @@ namespace Renci.SshNet
             {
                 if (AuthenticationMethods != null)
                 {
-                    foreach (var authenticationMethods in AuthenticationMethods.OfType<IDisposable>())
+                    foreach (var authenticationMethod in AuthenticationMethods)
                     {
-                        authenticationMethods.Dispose();
+                        var disposable = authenticationMethod as IDisposable;
+                        if (disposable != null)
+                        {
+                            disposable.Dispose();
+                        }
                     }
                 }
 

+ 6 - 3
src/Renci.SshNet/PrivateKeyConnectionInfo.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Collections.Generic;
-using System.Linq;
 using System.Collections.ObjectModel;
 
 namespace Renci.SshNet
@@ -167,9 +166,13 @@ namespace Renci.SshNet
                 // Dispose managed resources.
                 if (AuthenticationMethods != null)
                 {
-                    foreach (var authenticationMethods in AuthenticationMethods.OfType<IDisposable>())
+                    foreach (var authenticationMethod in AuthenticationMethods)
                     {
-                        authenticationMethods.Dispose();
+                        var disposable = authenticationMethod as IDisposable;
+                        if (disposable != null)
+                        {
+                            disposable.Dispose();
+                        }
                     }
                 }