Use pattern matching instead of as expression type checking
This commit is contained in:
parent
201004113e
commit
e2b16adec6
|
@ -148,8 +148,8 @@ namespace Marr.Data.QGen
|
||||||
if (right == null) // Value is not directly passed in as a constant
|
if (right == null) // Value is not directly passed in as a constant
|
||||||
{
|
{
|
||||||
var rightMemberExp = (rightExpression as MemberExpression);
|
var rightMemberExp = (rightExpression as MemberExpression);
|
||||||
var parentMemberExpression = rightMemberExp.Expression as MemberExpression;
|
|
||||||
if (parentMemberExpression != null) // Value is passed in as a property on a parent entity
|
if (rightMemberExp.Expression is MemberExpression parentMemberExpression) // Value is passed in as a property on a parent entity
|
||||||
{
|
{
|
||||||
string entityName = (rightMemberExp.Expression as MemberExpression).Member.Name;
|
string entityName = (rightMemberExp.Expression as MemberExpression).Member.Name;
|
||||||
var container = ((rightMemberExp.Expression as MemberExpression).Expression as ConstantExpression).Value;
|
var container = ((rightMemberExp.Expression as MemberExpression).Expression as ConstantExpression).Value;
|
||||||
|
|
|
@ -7,9 +7,8 @@ namespace NzbDrone.Common.EnsureThat
|
||||||
internal static string ToPath(this MemberExpression e)
|
internal static string ToPath(this MemberExpression e)
|
||||||
{
|
{
|
||||||
var path = "";
|
var path = "";
|
||||||
var parent = e.Expression as MemberExpression;
|
|
||||||
|
|
||||||
if (parent != null)
|
if (e.Expression is MemberExpression parent)
|
||||||
path = parent.ToPath() + ".";
|
path = parent.ToPath() + ".";
|
||||||
|
|
||||||
return path + e.Member.Name;
|
return path + e.Member.Name;
|
||||||
|
|
|
@ -160,9 +160,7 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||||
|
|
||||||
private void OnError(Exception ex)
|
private void OnError(Exception ex)
|
||||||
{
|
{
|
||||||
var webException = ex as WebException;
|
if (ex is WebException webException)
|
||||||
|
|
||||||
if (webException != null)
|
|
||||||
{
|
{
|
||||||
var response = webException.Response as HttpWebResponse;
|
var response = webException.Response as HttpWebResponse;
|
||||||
var statusCode = response?.StatusCode;
|
var statusCode = response?.StatusCode;
|
||||||
|
|
|
@ -2629,9 +2629,7 @@ namespace TinyIoC
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
var disposable = _instance as IDisposable;
|
if (_instance is IDisposable disposable)
|
||||||
|
|
||||||
if (disposable != null)
|
|
||||||
disposable.Dispose();
|
disposable.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2693,9 +2691,7 @@ namespace TinyIoC
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
var disposable = _instance.Target as IDisposable;
|
if (_instance.Target is IDisposable disposable)
|
||||||
|
|
||||||
if (disposable != null)
|
|
||||||
disposable.Dispose();
|
disposable.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2763,9 +2759,7 @@ namespace TinyIoC
|
||||||
if (this._Current == null)
|
if (this._Current == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var disposable = this._Current as IDisposable;
|
if (this._Current is IDisposable disposable)
|
||||||
|
|
||||||
if (disposable != null)
|
|
||||||
disposable.Dispose();
|
disposable.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,7 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
{
|
{
|
||||||
BeforeMigration = m =>
|
BeforeMigration = m =>
|
||||||
{
|
{
|
||||||
var migration = m as TMigration;
|
if (beforeMigration != null && m is TMigration migration)
|
||||||
if (beforeMigration != null && migration != null)
|
|
||||||
{
|
{
|
||||||
beforeMigration(migration);
|
beforeMigration(migration);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,8 @@ namespace NzbDrone.Core.Datastore.Migration
|
||||||
{
|
{
|
||||||
getFileChmodCmd.Transaction = tran;
|
getFileChmodCmd.Transaction = tran;
|
||||||
getFileChmodCmd.CommandText = @"SELECT Value FROM Config WHERE Key = 'filechmod'";
|
getFileChmodCmd.CommandText = @"SELECT Value FROM Config WHERE Key = 'filechmod'";
|
||||||
|
|
||||||
var fileChmod = getFileChmodCmd.ExecuteScalar() as string;
|
if (getFileChmodCmd.ExecuteScalar() is string fileChmod)
|
||||||
if (fileChmod != null)
|
|
||||||
{
|
{
|
||||||
if (fileChmod.IsNotNullOrWhiteSpace())
|
if (fileChmod.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
|
|
|
@ -88,8 +88,7 @@ namespace NzbDrone.Core.Download
|
||||||
}
|
}
|
||||||
catch (ReleaseDownloadException ex)
|
catch (ReleaseDownloadException ex)
|
||||||
{
|
{
|
||||||
var http429 = ex.InnerException as TooManyRequestsException;
|
if (ex.InnerException is TooManyRequestsException http429)
|
||||||
if (http429 != null)
|
|
||||||
{
|
{
|
||||||
_indexerStatusService.RecordFailure(remoteEpisode.Release.IndexerId, http429.RetryAfter);
|
_indexerStatusService.RecordFailure(remoteEpisode.Release.IndexerId, http429.RetryAfter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,8 +123,7 @@ namespace NzbDrone.Test.Common.AutoMoq
|
||||||
{
|
{
|
||||||
foreach (var registeredMock in _registeredMocks)
|
foreach (var registeredMock in _registeredMocks)
|
||||||
{
|
{
|
||||||
var mock = registeredMock.Value as Mock;
|
if (registeredMock.Value is Mock mock)
|
||||||
if (mock != null)
|
|
||||||
mock.VerifyAll();
|
mock.VerifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,7 @@ namespace Sonarr.Http.Validation
|
||||||
{
|
{
|
||||||
if (context.PropertyValue == null) return true;
|
if (context.PropertyValue == null) return true;
|
||||||
|
|
||||||
var collection = context.PropertyValue as IEnumerable<T>;
|
return context.PropertyValue is IEnumerable<T> collection && collection.Empty();
|
||||||
|
|
||||||
return collection != null && collection.Empty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue