mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Fix IDE0270: Null check can be simplified
This commit is contained in:
parent
58aeb11268
commit
a19094f4f3
8 changed files with 10 additions and 35 deletions
|
|
@ -99,10 +99,7 @@ internal partial class ConsoleManager : IServiceType
|
||||||
ArgumentNullException.ThrowIfNull(name);
|
ArgumentNullException.ThrowIfNull(name);
|
||||||
ArgumentNullException.ThrowIfNull(alias);
|
ArgumentNullException.ThrowIfNull(alias);
|
||||||
|
|
||||||
var target = this.FindEntry(name);
|
var target = this.FindEntry(name) ?? throw new EntryNotFoundException(name);
|
||||||
if (target == null)
|
|
||||||
throw new EntryNotFoundException(name);
|
|
||||||
|
|
||||||
if (this.FindEntry(alias) != null)
|
if (this.FindEntry(alias) != null)
|
||||||
throw new InvalidOperationException($"Entry '{alias}' already exists.");
|
throw new InvalidOperationException($"Entry '{alias}' already exists.");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,7 @@ internal sealed class ManifestResourceSharedImmediateTexture : SharedImmediateTe
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected override async Task<IDalamudTextureWrap> CreateTextureAsync(CancellationToken cancellationToken)
|
protected override async Task<IDalamudTextureWrap> CreateTextureAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await using var stream = this.assembly.GetManifestResourceStream(this.name);
|
await using var stream = this.assembly.GetManifestResourceStream(this.name) ?? throw new FileNotFoundException("The resource file could not be found.");
|
||||||
if (stream is null)
|
|
||||||
throw new FileNotFoundException("The resource file could not be found.");
|
|
||||||
|
|
||||||
var tm = await Service<TextureManager>.GetAsync();
|
var tm = await Service<TextureManager>.GetAsync();
|
||||||
var ms = new MemoryStream(stream.CanSeek ? checked((int)stream.Length) : 0);
|
var ms = new MemoryStream(stream.CanSeek ? checked((int)stream.Length) : 0);
|
||||||
await stream.CopyToAsync(ms, cancellationToken);
|
await stream.CopyToAsync(ms, cancellationToken);
|
||||||
|
|
|
||||||
|
|
@ -141,10 +141,7 @@ internal class PluginErrorHandler : IServiceType
|
||||||
private static Action<TDelegate, object[]> CreateInvoker<TDelegate>() where TDelegate : Delegate
|
private static Action<TDelegate, object[]> CreateInvoker<TDelegate>() where TDelegate : Delegate
|
||||||
{
|
{
|
||||||
var delegateType = typeof(TDelegate);
|
var delegateType = typeof(TDelegate);
|
||||||
var method = delegateType.GetMethod("Invoke");
|
var method = delegateType.GetMethod("Invoke") ?? throw new InvalidOperationException($"Delegate {delegateType} does not have an Invoke method.");
|
||||||
if (method == null)
|
|
||||||
throw new InvalidOperationException($"Delegate {delegateType} does not have an Invoke method.");
|
|
||||||
|
|
||||||
var parameters = method.GetParameters();
|
var parameters = method.GetParameters();
|
||||||
|
|
||||||
// Create parameters for the lambda
|
// Create parameters for the lambda
|
||||||
|
|
|
||||||
|
|
@ -1511,11 +1511,7 @@ internal class PluginManager : IInternalDisposableService
|
||||||
JsonConvert.SerializeObject(repoManifest, Formatting.Indented));
|
JsonConvert.SerializeObject(repoManifest, Formatting.Indented));
|
||||||
|
|
||||||
// Reload as a local manifest, add some attributes, and save again.
|
// Reload as a local manifest, add some attributes, and save again.
|
||||||
var tempManifest = LocalPluginManifest.Load(tempManifestFile);
|
var tempManifest = LocalPluginManifest.Load(tempManifestFile) ?? throw new Exception("Plugin had no valid manifest");
|
||||||
|
|
||||||
if (tempManifest == null)
|
|
||||||
throw new Exception("Plugin had no valid manifest");
|
|
||||||
|
|
||||||
if (tempManifest.InternalName != repoManifest.InternalName)
|
if (tempManifest.InternalName != repoManifest.InternalName)
|
||||||
{
|
{
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
|
|
|
||||||
|
|
@ -151,11 +151,7 @@ internal class ProfileManager : IServiceType
|
||||||
/// <returns>The newly cloned profile.</returns>
|
/// <returns>The newly cloned profile.</returns>
|
||||||
public Profile CloneProfile(Profile toClone)
|
public Profile CloneProfile(Profile toClone)
|
||||||
{
|
{
|
||||||
var newProfile = this.ImportProfile(toClone.Model.SerializeForShare());
|
return this.ImportProfile(toClone.Model.SerializeForShare()) ?? throw new Exception("New profile was null while cloning");
|
||||||
if (newProfile == null)
|
|
||||||
throw new Exception("New profile was null while cloning");
|
|
||||||
|
|
||||||
return newProfile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -119,13 +119,7 @@ internal class PluginRepository
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var data = await response.Content.ReadAsStringAsync();
|
var data = await response.Content.ReadAsStringAsync();
|
||||||
var pluginMaster = JsonConvert.DeserializeObject<List<RemotePluginManifest>>(data);
|
var pluginMaster = JsonConvert.DeserializeObject<List<RemotePluginManifest>>(data) ?? throw new Exception("Deserialized PluginMaster was null.");
|
||||||
|
|
||||||
if (pluginMaster == null)
|
|
||||||
{
|
|
||||||
throw new Exception("Deserialized PluginMaster was null.");
|
|
||||||
}
|
|
||||||
|
|
||||||
pluginMaster.Sort((pm1, pm2) => string.Compare(pm1.Name, pm2.Name, StringComparison.Ordinal));
|
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.
|
// Set the source for each remote manifest. Allows for checking if is 3rd party.
|
||||||
|
|
|
||||||
|
|
@ -356,10 +356,7 @@ internal static class Service<T> where T : IServiceType
|
||||||
|
|
||||||
private static async Task<T> ConstructObject(IReadOnlyCollection<object> additionalProvidedTypedObjects)
|
private static async Task<T> ConstructObject(IReadOnlyCollection<object> additionalProvidedTypedObjects)
|
||||||
{
|
{
|
||||||
var ctor = GetServiceConstructor();
|
var ctor = GetServiceConstructor() ?? throw new Exception($"Service \"{typeof(T).FullName}\" had no applicable constructor");
|
||||||
if (ctor == null)
|
|
||||||
throw new Exception($"Service \"{typeof(T).FullName}\" had no applicable constructor");
|
|
||||||
|
|
||||||
var args = await ResolveInjectedParameters(ctor.GetParameters(), additionalProvidedTypedObjects)
|
var args = await ResolveInjectedParameters(ctor.GetParameters(), additionalProvidedTypedObjects)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
using (Timings.Start($"{typeof(T).Name} Construct"))
|
using (Timings.Start($"{typeof(T).Name} Construct"))
|
||||||
|
|
|
||||||
|
|
@ -274,8 +274,9 @@ internal class ReliableFileStorage : IInternalDisposableService
|
||||||
throw new FileNotFoundException("Backup database was not available");
|
throw new FileNotFoundException("Backup database was not available");
|
||||||
|
|
||||||
var normalizedPath = NormalizePath(path);
|
var normalizedPath = NormalizePath(path);
|
||||||
var file = this.db.Table<DbFile>().FirstOrDefault(f => f.Path == normalizedPath && f.ContainerId == containerId);
|
var file = this.db.Table<DbFile>().FirstOrDefault(f => f.Path == normalizedPath && f.ContainerId == containerId)
|
||||||
return file == null ? throw new FileNotFoundException() : file.Data;
|
?? throw new FileNotFoundException();
|
||||||
|
return file.Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the file doesn't exist, immediately check the backup db
|
// If the file doesn't exist, immediately check the backup db
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue