Fix IDE0270: Null check can be simplified

This commit is contained in:
Haselnussbomber 2025-10-24 03:04:07 +02:00
parent 58aeb11268
commit a19094f4f3
No known key found for this signature in database
GPG key ID: BB905BB49E7295D1
8 changed files with 10 additions and 35 deletions

View file

@ -99,10 +99,7 @@ internal partial class ConsoleManager : IServiceType
ArgumentNullException.ThrowIfNull(name);
ArgumentNullException.ThrowIfNull(alias);
var target = this.FindEntry(name);
if (target == null)
throw new EntryNotFoundException(name);
var target = this.FindEntry(name) ?? throw new EntryNotFoundException(name);
if (this.FindEntry(alias) != null)
throw new InvalidOperationException($"Entry '{alias}' already exists.");

View file

@ -36,10 +36,7 @@ internal sealed class ManifestResourceSharedImmediateTexture : SharedImmediateTe
/// <inheritdoc/>
protected override async Task<IDalamudTextureWrap> CreateTextureAsync(CancellationToken cancellationToken)
{
await using var stream = this.assembly.GetManifestResourceStream(this.name);
if (stream is null)
throw new FileNotFoundException("The resource file could not be found.");
await using var stream = this.assembly.GetManifestResourceStream(this.name) ?? throw new FileNotFoundException("The resource file could not be found.");
var tm = await Service<TextureManager>.GetAsync();
var ms = new MemoryStream(stream.CanSeek ? checked((int)stream.Length) : 0);
await stream.CopyToAsync(ms, cancellationToken);

View file

@ -141,10 +141,7 @@ internal class PluginErrorHandler : IServiceType
private static Action<TDelegate, object[]> CreateInvoker<TDelegate>() where TDelegate : Delegate
{
var delegateType = typeof(TDelegate);
var method = delegateType.GetMethod("Invoke");
if (method == null)
throw new InvalidOperationException($"Delegate {delegateType} does not have an Invoke method.");
var method = delegateType.GetMethod("Invoke") ?? throw new InvalidOperationException($"Delegate {delegateType} does not have an Invoke method.");
var parameters = method.GetParameters();
// Create parameters for the lambda

View file

@ -1511,11 +1511,7 @@ internal class PluginManager : IInternalDisposableService
JsonConvert.SerializeObject(repoManifest, Formatting.Indented));
// Reload as a local manifest, add some attributes, and save again.
var tempManifest = LocalPluginManifest.Load(tempManifestFile);
if (tempManifest == null)
throw new Exception("Plugin had no valid manifest");
var tempManifest = LocalPluginManifest.Load(tempManifestFile) ?? throw new Exception("Plugin had no valid manifest");
if (tempManifest.InternalName != repoManifest.InternalName)
{
throw new Exception(

View file

@ -151,11 +151,7 @@ internal class ProfileManager : IServiceType
/// <returns>The newly cloned profile.</returns>
public Profile CloneProfile(Profile toClone)
{
var newProfile = this.ImportProfile(toClone.Model.SerializeForShare());
if (newProfile == null)
throw new Exception("New profile was null while cloning");
return newProfile;
return this.ImportProfile(toClone.Model.SerializeForShare()) ?? throw new Exception("New profile was null while cloning");
}
/// <summary>

View file

@ -119,13 +119,7 @@ internal class PluginRepository
response.EnsureSuccessStatusCode();
var data = await response.Content.ReadAsStringAsync();
var pluginMaster = JsonConvert.DeserializeObject<List<RemotePluginManifest>>(data);
if (pluginMaster == null)
{
throw new Exception("Deserialized PluginMaster was null.");
}
var pluginMaster = JsonConvert.DeserializeObject<List<RemotePluginManifest>>(data) ?? throw new Exception("Deserialized PluginMaster was null.");
pluginMaster.Sort((pm1, pm2) => string.Compare(pm1.Name, pm2.Name, StringComparison.Ordinal));
// Set the source for each remote manifest. Allows for checking if is 3rd party.

View file

@ -356,10 +356,7 @@ internal static class Service<T> where T : IServiceType
private static async Task<T> ConstructObject(IReadOnlyCollection<object> additionalProvidedTypedObjects)
{
var ctor = GetServiceConstructor();
if (ctor == null)
throw new Exception($"Service \"{typeof(T).FullName}\" had no applicable constructor");
var ctor = GetServiceConstructor() ?? throw new Exception($"Service \"{typeof(T).FullName}\" had no applicable constructor");
var args = await ResolveInjectedParameters(ctor.GetParameters(), additionalProvidedTypedObjects)
.ConfigureAwait(false);
using (Timings.Start($"{typeof(T).Name} Construct"))

View file

@ -274,8 +274,9 @@ internal class ReliableFileStorage : IInternalDisposableService
throw new FileNotFoundException("Backup database was not available");
var normalizedPath = NormalizePath(path);
var file = this.db.Table<DbFile>().FirstOrDefault(f => f.Path == normalizedPath && f.ContainerId == containerId);
return file == null ? throw new FileNotFoundException() : file.Data;
var file = this.db.Table<DbFile>().FirstOrDefault(f => f.Path == normalizedPath && f.ContainerId == containerId)
?? throw new FileNotFoundException();
return file.Data;
}
// If the file doesn't exist, immediately check the backup db