diff --git a/osu.Framework.Benchmarks/BenchmarkSlimReadOnlyList.cs b/osu.Framework.Benchmarks/BenchmarkSlimReadOnlyList.cs index 54a2d985a2..f7ab409d0a 100644 --- a/osu.Framework.Benchmarks/BenchmarkSlimReadOnlyList.cs +++ b/osu.Framework.Benchmarks/BenchmarkSlimReadOnlyList.cs @@ -10,7 +10,7 @@ namespace osu.Framework.Benchmarks [MemoryDiagnoser] public class BenchmarkSlimReadOnlyList { - private readonly List list = new List { 0, 1, 2, 3, 4, 5, 3, 2, 3, 1, 4, 5, -1 }; + private readonly List list = [0, 1, 2, 3, 4, 5, 3, 2, 3, 1, 4, 5, -1]; [Benchmark(Baseline = true)] public int List() diff --git a/osu.Framework.SourceGeneration.Tests/GeneratorTestHelper.cs b/osu.Framework.SourceGeneration.Tests/GeneratorTestHelper.cs index e632b4190f..5e5ffc9432 100644 --- a/osu.Framework.SourceGeneration.Tests/GeneratorTestHelper.cs +++ b/osu.Framework.SourceGeneration.Tests/GeneratorTestHelper.cs @@ -49,7 +49,7 @@ public static void VerifyMultiPhaseGeneratedSources(this GeneratorDriverRunResul int matches = 0; - foreach (var (filename, content) in files) + foreach ((string filename, string content) in files) { if (!generatedSources.TryGetValue(filename, out var source)) throw new Xunit.Sdk.XunitException($"Phase {phase}: Expected generated source {filename}, but it was not found"); diff --git a/osu.Framework.SourceGeneration.Tests/Verifiers/CSharpMultiPhaseSourceGeneratorVerifier_Test.cs b/osu.Framework.SourceGeneration.Tests/Verifiers/CSharpMultiPhaseSourceGeneratorVerifier_Test.cs index 781da8938a..ec63a94316 100644 --- a/osu.Framework.SourceGeneration.Tests/Verifiers/CSharpMultiPhaseSourceGeneratorVerifier_Test.cs +++ b/osu.Framework.SourceGeneration.Tests/Verifiers/CSharpMultiPhaseSourceGeneratorVerifier_Test.cs @@ -87,12 +87,12 @@ public void Verify() // Remove sources from previous phase that are not existing in the current phase if (phase > 0) { - foreach (var (filename, _) in multiPhaseSources[phase - 1].Where(old => sources.All(@new => @new.filename != old.filename))) + foreach ((string filename, string _) in multiPhaseSources[phase - 1].Where(old => sources.All(@new => @new.filename != old.filename))) compilation.RemoveSource(filename); } // Add sources for the current phase - foreach (var (filename, content) in sources) + foreach ((string filename, string content) in sources) { compilation.AddOrUpdateSource(filename, content); } diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneRearrangeableListContainer.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneRearrangeableListContainer.cs index 8b7de51eb0..2b5b7f952d 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneRearrangeableListContainer.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneRearrangeableListContainer.cs @@ -84,7 +84,7 @@ public void TestRemoveItem() List items = null!; - AddStep("get item references", () => items = new List(list.ItemMap.Values.ToList())); + AddStep("get item references", () => items = [..list.ItemMap.Values.ToList()]); for (int i = 0; i < item_count; i++) { diff --git a/osu.Framework/Audio/Sample/ISample.cs b/osu.Framework/Audio/Sample/ISample.cs index c1f4158183..b2bcea20e0 100644 --- a/osu.Framework/Audio/Sample/ISample.cs +++ b/osu.Framework/Audio/Sample/ISample.cs @@ -26,7 +26,7 @@ public interface ISample : IAdjustableAudioComponent /// /// Whether this is fully loaded. /// - public bool IsLoaded { get; } + bool IsLoaded { get; } /// /// The number of times this sample (as identified by name) can be played back concurrently. diff --git a/osu.Framework/Audio/Track/ITrack.cs b/osu.Framework/Audio/Track/ITrack.cs index 35ff84bdf0..b56d5c720a 100644 --- a/osu.Framework/Audio/Track/ITrack.cs +++ b/osu.Framework/Audio/Track/ITrack.cs @@ -54,7 +54,7 @@ public interface ITrack : IAdjustableClock, IHasAmplitudes, IAdjustableAudioComp /// /// Whether this track has finished playing back. /// - public bool HasCompleted { get; } + bool HasCompleted { get; } /// /// Restarts this track from the while retaining adjustments. diff --git a/osu.Framework/Bindables/IBindableWithCurrent.cs b/osu.Framework/Bindables/IBindableWithCurrent.cs index 5c5987f7ea..df1c97018f 100644 --- a/osu.Framework/Bindables/IBindableWithCurrent.cs +++ b/osu.Framework/Bindables/IBindableWithCurrent.cs @@ -16,7 +16,7 @@ public interface IBindableWithCurrent : IBindable, IHasCurrentValue /// If the value type is one supported by the , an instance of will be returned. /// Otherwise an instance of will be returned instead. /// - public static IBindableWithCurrent Create() + static IBindableWithCurrent Create() { if (Validation.IsSupportedBindableNumberType()) return (IBindableWithCurrent)Activator.CreateInstance(typeof(BindableNumberWithCurrent<>).MakeGenericType(typeof(T)), default(T)); diff --git a/osu.Framework/Configuration/ConfigManager.cs b/osu.Framework/Configuration/ConfigManager.cs index 98b711c6ba..abe46d67d1 100644 --- a/osu.Framework/Configuration/ConfigManager.cs +++ b/osu.Framework/Configuration/ConfigManager.cs @@ -296,10 +296,10 @@ protected Bindable GetOriginalBindable(TLookup lookup) { if (ConfigStore.TryGetValue(lookup, out IBindable obj)) { - if (!(obj is Bindable)) + if (!(obj is Bindable value)) throw new InvalidCastException($"Cannot convert bindable of type {obj.GetType()} retrieved from {nameof(ConfigManager)} to {typeof(Bindable)}."); - return (Bindable)obj; + return value; } return null; diff --git a/osu.Framework/Graphics/Animations/IAnimation.cs b/osu.Framework/Graphics/Animations/IAnimation.cs index d515778427..12e67f951f 100644 --- a/osu.Framework/Graphics/Animations/IAnimation.cs +++ b/osu.Framework/Graphics/Animations/IAnimation.cs @@ -11,12 +11,12 @@ public interface IAnimation /// /// The duration of the animation. /// - public double Duration { get; } + double Duration { get; } /// /// True if the animation has finished playing, false otherwise. /// - public bool FinishedPlaying => !Loop && PlaybackPosition > Duration; + bool FinishedPlaying => !Loop && PlaybackPosition > Duration; /// /// True if the animation is playing, false otherwise. true by default. @@ -37,6 +37,6 @@ public interface IAnimation /// /// The current position of playback. /// - public double PlaybackPosition { get; set; } + double PlaybackPosition { get; set; } } } diff --git a/osu.Framework/Graphics/Audio/WaveformGraph.cs b/osu.Framework/Graphics/Audio/WaveformGraph.cs index d05a2f7f76..089f6e5fbb 100644 --- a/osu.Framework/Graphics/Audio/WaveformGraph.cs +++ b/osu.Framework/Graphics/Audio/WaveformGraph.cs @@ -297,7 +297,7 @@ public override void ApplyState() { // Late initialise list to use a sane initial capacity. if (points == null) - points = new List(Source.resampledPoints ?? Enumerable.Empty()); + points = [..Source.resampledPoints ?? Enumerable.Empty()]; else { points.Clear(); diff --git a/osu.Framework/Graphics/Containers/VirtualisedListContainer.cs b/osu.Framework/Graphics/Containers/VirtualisedListContainer.cs index 9c27d2324c..8b4cfcd9af 100644 --- a/osu.Framework/Graphics/Containers/VirtualisedListContainer.cs +++ b/osu.Framework/Graphics/Containers/VirtualisedListContainer.cs @@ -129,7 +129,7 @@ private void itemsChanged(object? sender, NotifyCollectionChangedEventArgs e) allMoves.Add((items[i], i - 1)); } - foreach (var (item, newPosition) in allMoves) + foreach ((var item, int newPosition) in allMoves) Items.Move(item, newPosition); break; diff --git a/osu.Framework/Graphics/Primitives/Vector2I.cs b/osu.Framework/Graphics/Primitives/Vector2I.cs index 76b445998d..f490772772 100644 --- a/osu.Framework/Graphics/Primitives/Vector2I.cs +++ b/osu.Framework/Graphics/Primitives/Vector2I.cs @@ -45,10 +45,10 @@ public Vector2I(int x, int y) public override readonly bool Equals(object obj) { - if (!(obj is Vector2I)) + if (!(obj is Vector2I i)) return false; - return Equals((Vector2I)obj); + return Equals(i); } [SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")] diff --git a/osu.Framework/Graphics/Rendering/IRenderer.cs b/osu.Framework/Graphics/Rendering/IRenderer.cs index b401ecfd37..78ab6a9793 100644 --- a/osu.Framework/Graphics/Rendering/IRenderer.cs +++ b/osu.Framework/Graphics/Rendering/IRenderer.cs @@ -24,25 +24,25 @@ public interface IRenderer /// Maximum number of s a can draw with. /// This is a carefully-chosen number to enable the update and draw threads to work concurrently without causing unnecessary load. /// - public const int MAX_DRAW_NODES = 3; + const int MAX_DRAW_NODES = 3; - public const int MAX_MIPMAP_LEVELS = 3; + const int MAX_MIPMAP_LEVELS = 3; - public const int VERTICES_PER_TRIANGLE = 4; + const int VERTICES_PER_TRIANGLE = 4; - public const int VERTICES_PER_QUAD = 4; + const int VERTICES_PER_QUAD = 4; - public const int INDICES_PER_QUAD = VERTICES_PER_QUAD + 2; + const int INDICES_PER_QUAD = VERTICES_PER_QUAD + 2; /// /// Maximum number of vertices in a linear vertex buffer. /// - public const int MAX_VERTICES = ushort.MaxValue; + const int MAX_VERTICES = ushort.MaxValue; /// /// Maximum number of quads in a quad vertex buffer. /// - public const int MAX_QUADS = ushort.MaxValue / INDICES_PER_QUAD; + const int MAX_QUADS = ushort.MaxValue / INDICES_PER_QUAD; /// /// Enables or disables vertical sync. @@ -353,7 +353,7 @@ public interface IRenderer /// /// Returns an image containing the content of a framebuffer. /// - public Image? ExtractFrameBufferData(IFrameBuffer frameBuffer); + Image? ExtractFrameBufferData(IFrameBuffer frameBuffer); /// /// Creates a new . diff --git a/osu.Framework/Graphics/Veldrid/Pipelines/GraphicsPipeline.cs b/osu.Framework/Graphics/Veldrid/Pipelines/GraphicsPipeline.cs index 76ff428298..c9c70a1fee 100644 --- a/osu.Framework/Graphics/Veldrid/Pipelines/GraphicsPipeline.cs +++ b/osu.Framework/Graphics/Veldrid/Pipelines/GraphicsPipeline.cs @@ -253,7 +253,7 @@ public void DrawVertices(global::Veldrid.PrimitiveTopology topology, int vertexS Array.Resize(ref pipelineDesc.ResourceLayouts, currentShader.LayoutCount); // Activate texture layouts. - foreach (var (unit, _) in attachedTextures) + foreach ((int unit, var _) in attachedTextures) { var layout = currentShader.GetTextureLayout(unit); if (layout == null) @@ -263,7 +263,7 @@ public void DrawVertices(global::Veldrid.PrimitiveTopology topology, int vertexS } // Activate uniform buffer layouts. - foreach (var (name, _) in attachedUniformBuffers) + foreach ((string name, var _) in attachedUniformBuffers) { var layout = currentShader.GetUniformBufferLayout(name); if (layout == null) @@ -276,7 +276,7 @@ public void DrawVertices(global::Veldrid.PrimitiveTopology topology, int vertexS Commands.SetPipeline(createPipeline()); // Activate texture resources. - foreach (var (unit, texture) in attachedTextures) + foreach ((int unit, var texture) in attachedTextures) { var layout = currentShader.GetTextureLayout(unit); if (layout == null) @@ -286,7 +286,7 @@ public void DrawVertices(global::Veldrid.PrimitiveTopology topology, int vertexS } // Activate uniform buffer resources. - foreach (var (name, buffer) in attachedUniformBuffers) + foreach ((string name, var buffer) in attachedUniformBuffers) { var layout = currentShader.GetUniformBufferLayout(name); if (layout == null) diff --git a/osu.Framework/Logging/Logger.cs b/osu.Framework/Logging/Logger.cs index 64b281d9b7..33570b6cf7 100644 --- a/osu.Framework/Logging/Logger.cs +++ b/osu.Framework/Logging/Logger.cs @@ -91,7 +91,7 @@ public static Storage Storage private readonly GlobalStatistic logCount; - private static readonly HashSet reserved_names = new HashSet(Enum.GetNames().Select(n => n.ToLowerInvariant())); + private static readonly HashSet reserved_names = [..Enum.GetNames().Select(n => n.ToLowerInvariant())]; private Logger(LoggingTarget target = LoggingTarget.Runtime) : this(target.ToString(), false) diff --git a/osu.Framework/Testing/TestScene.cs b/osu.Framework/Testing/TestScene.cs index d0b76e9ae4..bee28451f6 100644 --- a/osu.Framework/Testing/TestScene.cs +++ b/osu.Framework/Testing/TestScene.cs @@ -571,7 +571,7 @@ public override void BeforeTest(ITest test) }); } - if (TestContext.CurrentContext.Test.MethodName != nameof(TestScene.TestConstructor)) + if (TestContext.CurrentContext.Test.MethodName != nameof(TestConstructor)) testScene.Schedule(() => testScene.StepsContainer.Clear()); testScene.RunSetUpSteps(); diff --git a/osu.Framework/Text/TextBuilder.cs b/osu.Framework/Text/TextBuilder.cs index 045f43eb52..82a76def20 100644 --- a/osu.Framework/Text/TextBuilder.cs +++ b/osu.Framework/Text/TextBuilder.cs @@ -356,12 +356,10 @@ private bool tryCreateGlyph(char character, out TextBuilderGlyph glyph) return tryGetGlyph(character, font, store) ?? tryGetGlyph(fallbackCharacter, font, store); - static ITexturedCharacterGlyph? tryGetGlyph(char character, FontUsage font, ITexturedGlyphLookupStore store) - { - return store.Get(font.FontName, character) - ?? store.Get(font.FontNameNoFamily, character) - ?? store.Get(string.Empty, character); - } + static ITexturedCharacterGlyph? tryGetGlyph(char character, FontUsage font, ITexturedGlyphLookupStore store) => + store.Get(font.FontName, character) + ?? store.Get(font.FontNameNoFamily, character) + ?? store.Get(string.Empty, character); } } } diff --git a/osu.Framework/Utils/IncrementalBSplineBuilder.cs b/osu.Framework/Utils/IncrementalBSplineBuilder.cs index df19e7e96c..4ee6b16bbc 100644 --- a/osu.Framework/Utils/IncrementalBSplineBuilder.cs +++ b/osu.Framework/Utils/IncrementalBSplineBuilder.cs @@ -17,8 +17,8 @@ namespace osu.Framework.Utils /// public class IncrementalBSplineBuilder { - private readonly List inputPath = new List(); - private readonly List cumulativeInputPathLength = new List(); + private readonly List inputPath = []; + private readonly List cumulativeInputPathLength = []; private static Vector2 getPathAt(List path, List cumulativeDistances, float t) { @@ -71,12 +71,12 @@ private static float getAbsWindingAt(List path, List cumulativeD private readonly Cached> outputCache = new Cached> { - Value = new List() + Value = [] }; private readonly Cached>> controlPoints = new Cached>> { - Value = new List>() + Value = [] }; private bool shouldOptimiseLastSegment; @@ -334,7 +334,7 @@ private void updateLastSegment(List vertices, List distances, Li // Initialize control points for the last segment int i = segments.Count - 1; var lastSegment = segments[i]; - var (cps, segmentPath, totalWinding) = initializeSegment(vertices, distances, cornerTs[i], cornerTs[i + 1]); + (var cps, var segmentPath, float totalWinding) = initializeSegment(vertices, distances, cornerTs[i], cornerTs[i + 1]); // Make sure the last segment has the correct end-points if (lastSegment.Count >= 1) @@ -401,7 +401,7 @@ private void regenerateLastApproximatedSegment() if (vertices.Count < 2) { - controlPoints.Value = new List> { vertices }; + controlPoints.Value = [vertices]; return; } @@ -424,7 +424,7 @@ private void regenerateLastApproximatedSegment() // The previous segment may have been shortened by the addition of a corner. // We have to remove the extra control points and re-optimize the path. updateLastSegment(vertices, distances, cornerTs, segments, 100, false); - segments.Add(new List()); + segments.Add([]); } if (finishedDrawing) @@ -450,11 +450,11 @@ private void regenerateFullApproximatedPath() if (vertices.Count < 2) { - controlPoints.Value = new List> { vertices }; + controlPoints.Value = [vertices]; return; } - controlPoints.Value = new List>(); + controlPoints.Value = []; Debug.Assert(vertices.Count == distances.Count + 1); var cornerTs = detectCorners(vertices, distances); @@ -463,7 +463,7 @@ private void regenerateFullApproximatedPath() for (int i = 1; i < cornerTs.Count; ++i) { - var (cps, segmentPath, totalWinding) = initializeSegment(vertices, distances, cornerTs[i - 1], cornerTs[i]); + (var cps, var segmentPath, float totalWinding) = initializeSegment(vertices, distances, cornerTs[i - 1], cornerTs[i]); if (cps.Count > 2 && cps.Count < 100) { @@ -480,7 +480,7 @@ private void regenerateFullApproximatedPath() private void redrawApproximatedPath() { - outputCache.Value = new List(); + outputCache.Value = []; foreach (var segment in ControlPoints) { @@ -496,8 +496,8 @@ public void Clear() inputPath.Clear(); cumulativeInputPathLength.Clear(); - controlPoints.Value = new List>(); - outputCache.Value = new List(); + controlPoints.Value = []; + outputCache.Value = []; shouldOptimiseLastSegment = false; finishedDrawing = false; diff --git a/osu.Framework/Utils/NumberFormatter.cs b/osu.Framework/Utils/NumberFormatter.cs index 57966f3623..d60c98bea2 100644 --- a/osu.Framework/Utils/NumberFormatter.cs +++ b/osu.Framework/Utils/NumberFormatter.cs @@ -10,7 +10,7 @@ namespace osu.Framework.Utils /// public static class NumberFormatter { - private static readonly string[] suffixes = { "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" }; + private static readonly string[] suffixes = ["y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y"]; /// /// Prints the number with at most two decimal digits, followed by a magnitude suffic (k, M, G, T, etc.) depending on the magnitude of the number. If the number is diff --git a/osu.Framework/Utils/PathApproximator.cs b/osu.Framework/Utils/PathApproximator.cs index 9348d9c3a6..8be8cc3bcd 100644 --- a/osu.Framework/Utils/PathApproximator.cs +++ b/osu.Framework/Utils/PathApproximator.cs @@ -57,7 +57,7 @@ public static Vector2[] BSplineToBezier(ReadOnlySpan controlPoints, int // Spline fitting does not make sense when the input contains no points or just one point. In this case // the user likely wants this function to behave like a no-op. if (controlPoints.Length < 2) - return controlPoints.Length == 0 ? Array.Empty() : new[] { controlPoints[0] }; + return controlPoints.Length == 0 ? [] : [controlPoints[0]]; return bSplineToBezierInternal(controlPoints, ref degree).SelectMany(segment => segment).ToArray(); } @@ -86,14 +86,14 @@ public static List BSplineToPiecewiseLinear(ReadOnlySpan contr // Spline fitting does not make sense when the input contains no points or just one point. In this case // the user likely wants this function to behave like a no-op. if (controlPoints.Length < 2) - return controlPoints.Length == 0 ? new List() : new List { controlPoints[0] }; + return controlPoints.Length == 0 ? [] : [controlPoints[0]]; // With fewer control points than the degree, splines can not be unambiguously fitted. Rather than erroring // out, we set the degree to the minimal number that permits a unique fit to avoid special casing in // incremental spline building algorithms that call this function. degree = Math.Min(degree, controlPoints.Length - 1); - List output = new List(); + List output = []; int pointCount = controlPoints.Length - 1; Stack toFlatten = bSplineToBezierInternal(controlPoints, ref degree); @@ -211,11 +211,11 @@ public static RectangleF CircularArcBoundingBox(ReadOnlySpan controlPoi // We find the bounding box using the end-points, as well as // each 90 degree angle inside the range of the arc - List points = new List - { + List points = + [ controlPoints[0], controlPoints[2] - }; + ]; const double right_angle = Math.PI / 2; double step = right_angle * pr.Direction;