diff options
author | Kenneth Hsu <kennethhsu@gmail.com> | 2019-09-30 06:16:28 +0300 |
---|---|---|
committer | Kenneth Hsu <kennethhsu@gmail.com> | 2019-10-19 20:15:38 +0300 |
commit | afab61a05be83c5ffd4fdf9a732791b6d9ec2291 (patch) | |
tree | 3db4d9cc9d6b2488719aa15bff6e61a9b972ff46 /Duplicati/CommandLine | |
parent | e0d5a7d43eaf34535f1811d891d9a7afc062a413 (diff) |
Use pattern matching to simplify casts.
Diffstat (limited to 'Duplicati/CommandLine')
-rw-r--r-- | Duplicati/CommandLine/BackendTester/Program.cs | 12 | ||||
-rw-r--r-- | Duplicati/CommandLine/Program.cs | 5 |
2 files changed, 9 insertions, 8 deletions
diff --git a/Duplicati/CommandLine/BackendTester/Program.cs b/Duplicati/CommandLine/BackendTester/Program.cs index b29031b32..3f4285ef0 100644 --- a/Duplicati/CommandLine/BackendTester/Program.cs +++ b/Duplicati/CommandLine/BackendTester/Program.cs @@ -342,11 +342,11 @@ namespace Duplicati.CommandLine.BackendTester try
{
- if (backend is Library.Interface.IStreamingBackend && !disableStreaming)
+ if (backend is IStreamingBackend streamingBackend && !disableStreaming)
{
using (System.IO.FileStream fs = new System.IO.FileStream(cf, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
using (NonSeekableStream nss = new NonSeekableStream(fs))
- (backend as Library.Interface.IStreamingBackend).Get(files[i].remotefilename, nss);
+ streamingBackend.Get(files[i].remotefilename, nss);
}
else
backend.Get(files[i].remotefilename, cf);
@@ -453,8 +453,8 @@ namespace Duplicati.CommandLine.BackendTester finally
{
foreach (Library.Interface.IGenericModule m in loadedModules)
- if (m is IDisposable)
- ((IDisposable)m).Dispose();
+ if (m is IDisposable disposable)
+ disposable.Dispose();
}
return true;
@@ -467,11 +467,11 @@ namespace Duplicati.CommandLine.BackendTester try
{
- if (backend is Library.Interface.IStreamingBackend && !disableStreaming)
+ if (backend is IStreamingBackend streamingBackend && !disableStreaming)
{
using (System.IO.FileStream fs = new System.IO.FileStream(localfilename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
using (NonSeekableStream nss = new NonSeekableStream(fs))
- (backend as Library.Interface.IStreamingBackend).PutAsync(remotefilename, nss, CancellationToken.None).Wait();
+ streamingBackend.PutAsync(remotefilename, nss, CancellationToken.None).Wait();
}
else
backend.PutAsync(remotefilename, localfilename, CancellationToken.None).Wait();
diff --git a/Duplicati/CommandLine/Program.cs b/Duplicati/CommandLine/Program.cs index 1cad210cf..b5e205f17 100644 --- a/Duplicati/CommandLine/Program.cs +++ b/Duplicati/CommandLine/Program.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.Linq;
using Duplicati.Library.Localization.Short;
using System.IO;
+using Duplicati.Library.Interface;
using Duplicati.Library.Logging;
namespace Duplicati.CommandLine
@@ -242,10 +243,10 @@ namespace Duplicati.CommandLine while (ex is System.Reflection.TargetInvocationException && ex.InnerException != null)
ex = ex.InnerException;
- if (ex is Duplicati.Library.Interface.UserInformationException && !verboseErrors)
+ if (ex is UserInformationException exception && !verboseErrors)
{
errwriter.WriteLine();
- errwriter.WriteLine("ErrorID: {0}", ((Duplicati.Library.Interface.UserInformationException)ex).HelpID);
+ errwriter.WriteLine("ErrorID: {0}", exception.HelpID);
errwriter.WriteLine(ex.Message);
}
else if (!(ex is Library.Interface.CancelException))
|