Simplify dictionary lookups with GetValueOrDefault()

This is flagged by ReShaper under ID
`CanSimplifyDictionaryTryGetValueWithGetValueOrDefault`.
This commit is contained in:
Susko3
2025-12-13 03:50:45 +01:00
parent 19cf80488e
commit c44324c671
4 changed files with 6 additions and 8 deletions

View File

@@ -79,7 +79,7 @@ namespace osu.Framework.Tests.Visual.Localisation
{
}
public string? Get(string key) => translations.TryGetValue(key, out string? value) ? value : null;
public string? Get(string key) => translations.GetValueOrDefault(key);
public Task<string?> GetAsync(string key, CancellationToken cancellationToken = default) => Task.FromResult(Get(key));

View File

@@ -3,6 +3,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using osu.Framework.Graphics.Rendering;
using osu.Framework.IO.Stores;
@@ -55,7 +56,7 @@ namespace osu.Framework.Graphics.Shaders
/// <param name="fragment">The fragment shader name.</param>
/// <returns>A cached <see cref="IShader"/> instance, if existing.</returns>
public virtual IShader? GetCachedShader(string vertex, string fragment)
=> shaderCache.TryGetValue((vertex, fragment), out IShader? shader) ? shader : null;
=> shaderCache.GetValueOrDefault((vertex, fragment));
/// <summary>
/// Attempts to retrieve an already-cached shader part.
@@ -63,7 +64,7 @@ namespace osu.Framework.Graphics.Shaders
/// <param name="name">The name of the shader part.</param>
/// <returns>A cached <see cref="IShaderPart"/> instance, if existing.</returns>
public virtual IShaderPart? GetCachedShaderPart(string name)
=> partCache.TryGetValue(name, out IShaderPart? part) ? part : null;
=> partCache.GetValueOrDefault(name);
/// <summary>
/// Attempts to retrieve the raw data for a shader file.

View File

@@ -368,10 +368,7 @@ namespace osu.Framework.Graphics.Transforms
return min;
}
if (lastAppliedTransformIndices.TryGetValue(targetMember, out int val))
return val;
return 0;
return lastAppliedTransformIndices.GetValueOrDefault(targetMember, 0);
}
/// <summary>

View File

@@ -209,7 +209,7 @@ namespace osu.Framework.Input
/// <param name="button">The button to find the manager for.</param>
/// <returns>The <see cref="MouseButtonEventManager"/>.</returns>
public MouseButtonEventManager GetButtonEventManagerFor(MouseButton button) =>
mouseButtonEventManagers.TryGetValue(button, out var manager) ? manager : null;
mouseButtonEventManagers.GetValueOrDefault(button);
/// <summary>
/// Create a <see cref="KeyEventManager"/> for a specified key.