mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
Simplify dictionary lookups with GetValueOrDefault()
This is flagged by ReShaper under ID `CanSimplifyDictionaryTryGetValueWithGetValueOrDefault`.
This commit is contained in:
@@ -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));
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user