Skip to content

Commit c44324c

Browse files
committed
Simplify dictionary lookups with GetValueOrDefault()
This is flagged by ReShaper under ID `CanSimplifyDictionaryTryGetValueWithGetValueOrDefault`.
1 parent 19cf804 commit c44324c

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

osu.Framework.Tests/Visual/Localisation/LocalisationTestScene.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public TestLocalisationStore(string locale, IReadOnlyDictionary<string, string>
7979
{
8080
}
8181

82-
public string? Get(string key) => translations.TryGetValue(key, out string? value) ? value : null;
82+
public string? Get(string key) => translations.GetValueOrDefault(key);
8383

8484
public Task<string?> GetAsync(string key, CancellationToken cancellationToken = default) => Task.FromResult(Get(key));
8585

osu.Framework/Graphics/Shaders/ShaderManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Concurrent;
6+
using System.Collections.Generic;
67
using System.IO;
78
using osu.Framework.Graphics.Rendering;
89
using osu.Framework.IO.Stores;
@@ -55,15 +56,15 @@ public IShader Load(string vertex, string fragment)
5556
/// <param name="fragment">The fragment shader name.</param>
5657
/// <returns>A cached <see cref="IShader"/> instance, if existing.</returns>
5758
public virtual IShader? GetCachedShader(string vertex, string fragment)
58-
=> shaderCache.TryGetValue((vertex, fragment), out IShader? shader) ? shader : null;
59+
=> shaderCache.GetValueOrDefault((vertex, fragment));
5960

6061
/// <summary>
6162
/// Attempts to retrieve an already-cached shader part.
6263
/// </summary>
6364
/// <param name="name">The name of the shader part.</param>
6465
/// <returns>A cached <see cref="IShaderPart"/> instance, if existing.</returns>
6566
public virtual IShaderPart? GetCachedShaderPart(string name)
66-
=> partCache.TryGetValue(name, out IShaderPart? part) ? part : null;
67+
=> partCache.GetValueOrDefault(name);
6768

6869
/// <summary>
6970
/// Attempts to retrieve the raw data for a shader file.

osu.Framework/Graphics/Transforms/TargetGroupingTransformTracker.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,7 @@ private int getLastAppliedIndex(string targetMember = null)
368368
return min;
369369
}
370370

371-
if (lastAppliedTransformIndices.TryGetValue(targetMember, out int val))
372-
return val;
373-
374-
return 0;
371+
return lastAppliedTransformIndices.GetValueOrDefault(targetMember, 0);
375372
}
376373

377374
/// <summary>

osu.Framework/Input/InputManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ protected virtual MouseButtonEventManager CreateButtonEventManagerFor(MouseButto
209209
/// <param name="button">The button to find the manager for.</param>
210210
/// <returns>The <see cref="MouseButtonEventManager"/>.</returns>
211211
public MouseButtonEventManager GetButtonEventManagerFor(MouseButton button) =>
212-
mouseButtonEventManagers.TryGetValue(button, out var manager) ? manager : null;
212+
mouseButtonEventManagers.GetValueOrDefault(button);
213213

214214
/// <summary>
215215
/// Create a <see cref="KeyEventManager"/> for a specified key.

0 commit comments

Comments
 (0)