Pārlūkot izejas kodu

Applying some code analyzer suggestions

Source commit: 2236553766f964d4e7580e5576822f423596e337
Martin Prikryl 4 gadi atpakaļ
vecāks
revīzija
4e798aa1c4

+ 6 - 6
dotnet/Session.cs

@@ -6,9 +6,13 @@ using System.Globalization;
 using System.Runtime.InteropServices;
 using System.Threading;
 using System.Xml;
+#if !NETSTANDARD
 using Microsoft.Win32;
+#endif
 using System.Diagnostics;
+#if !NETSTANDARD
 using System.Security;
+#endif
 using System.Text.RegularExpressions;
 using System.Linq;
 
@@ -812,10 +816,6 @@ namespace WinSCP
         {
             using (Logger.CreateCallstackAndLock())
             {
-                if (stream == null)
-                {
-                    throw Logger.WriteException(new ArgumentNullException(nameof(stream)));
-                }
                 if (remoteFilePath == null)
                 {
                     throw Logger.WriteException(new ArgumentNullException(nameof(remoteFilePath)));
@@ -824,7 +824,7 @@ namespace WinSCP
                 {
                     throw Logger.WriteException(new InvalidOperationException("Already uploading from a stream"));
                 }
-                _process.StdIn = stream;
+                _process.StdIn = stream ?? throw Logger.WriteException(new ArgumentNullException(nameof(stream)));
                 try
                 {
                     remoteFilePath = RemotePath.EscapeFileMask(remoteFilePath);
@@ -1461,7 +1461,7 @@ namespace WinSCP
                                 }
                             }
 
-                            if (difference.Action == default(SynchronizationAction))
+                            if (difference.Action == default)
                             {
                                 throw Logger.WriteException(new InvalidOperationException("No action tag found"));
                             }

+ 1 - 1
dotnet/internal/ElementLogReader.cs

@@ -86,6 +86,6 @@ namespace WinSCP
         private readonly string _localName;
         private readonly int _depth;
         protected bool _read;
-        private string _token;
+        private readonly string _token;
     }
 }

+ 4 - 0
dotnet/internal/ExeSessionProcess.cs

@@ -4,12 +4,16 @@ using System.Diagnostics;
 using System.Globalization;
 using System.IO;
 using System.Threading;
+#if !NETSTANDARD
 using Microsoft.Win32;
+#endif
 using Microsoft.Win32.SafeHandles;
 using System.Runtime.InteropServices;
 using System.Reflection;
+#if !NETSTANDARD
 using System.Security.Principal;
 using System.Security.AccessControl;
+#endif
 using System.ComponentModel;
 using System.Security.Cryptography;
 

+ 0 - 1
dotnet/internal/ISessionProcess.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Diagnostics;
 
 namespace WinSCP
 {

+ 1 - 1
dotnet/internal/Job.cs

@@ -67,6 +67,6 @@ namespace WinSCP
         }
 
         private IntPtr _handle;
-        private Logger _logger;
+        private readonly Logger _logger;
     }
 }

+ 1 - 1
dotnet/internal/Logger.cs

@@ -406,7 +406,7 @@ namespace WinSCP
         private readonly Dictionary<int, int> _indents = new Dictionary<int, int>();
         private readonly object _logLock = new object();
 #if !NETSTANDARD
-        private List<PerformanceCounter> _performanceCounters = new List<PerformanceCounter>();
+        private readonly List<PerformanceCounter> _performanceCounters = new List<PerformanceCounter>();
 #endif
         private int _logLevel;
     }

+ 1 - 1
dotnet/internal/PatientFileStream.cs

@@ -148,6 +148,6 @@ namespace WinSCP
         }
 
         private FileStream _stream;
-        private Session _session;
+        private readonly Session _session;
     }
 }

+ 1 - 1
dotnet/internal/ProgressHandler.cs

@@ -17,6 +17,6 @@ namespace WinSCP
             }
         }
 
-        private Session _session;
+        private readonly Session _session;
     }
 }