Add IsError = true and mark relevant delegates as static

This commit is contained in:
Susko3
2024-02-05 14:40:41 +01:00
parent cc034ee40b
commit 09549f3a2f
4 changed files with 7 additions and 6 deletions

View File

@@ -59,7 +59,7 @@ namespace osu.Framework.Allocation
/// </summary>
/// <param name="sender">The sender which should appear in the <paramref name="action"/> callback.</param>
/// <param name="action">The action to invoke during disposal.</param>
public InvokeOnDisposal(T sender, [RequireStaticDelegate] Action<T> action)
public InvokeOnDisposal(T sender, [RequireStaticDelegate(IsError = true)] Action<T> action)
{
this.sender = sender;
this.action = action ?? throw new ArgumentNullException(nameof(action));

View File

@@ -63,7 +63,7 @@ namespace osu.Framework.Allocation
/// </summary>
/// <param name="sender">The sender which should appear in the <paramref name="action"/> callback.</param>
/// <param name="action">The action to invoke during disposal.</param>
public ValueInvokeOnDisposal(T sender, [RequireStaticDelegate] Action<T> action)
public ValueInvokeOnDisposal(T sender, [RequireStaticDelegate(IsError = true)] Action<T> action)
{
this.sender = sender;
this.action = action ?? throw new ArgumentNullException(nameof(action));

View File

@@ -150,7 +150,7 @@ namespace osu.Framework.Graphics
frameBuffer.Bind();
return new ValueInvokeOnDisposal<IFrameBuffer>(frameBuffer, b => b.Unbind());
return new ValueInvokeOnDisposal<IFrameBuffer>(frameBuffer, static b => b.Unbind());
}
private IDisposable establishFrameBufferViewport(IRenderer renderer)
@@ -175,7 +175,7 @@ namespace osu.Framework.Graphics
renderer.PushScissor(new RectangleI(0, 0, (int)frameBufferSize.X, (int)frameBufferSize.Y));
renderer.PushScissorOffset(screenSpaceMaskingRect.Location);
return new ValueInvokeOnDisposal<(BufferedDrawNode node, IRenderer renderer)>((this, renderer), tup => tup.node.returnViewport(tup.renderer));
return new ValueInvokeOnDisposal<(BufferedDrawNode node, IRenderer renderer)>((this, renderer), static tup => tup.node.returnViewport(tup.renderer));
}
private void returnViewport(IRenderer renderer)

View File

@@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Statistics;
@@ -22,7 +23,7 @@ namespace osu.Framework.Platform
public static NativeMemoryLease AddMemory(object source, long amount)
{
getStatistic(source).Value += amount;
return new NativeMemoryLease((source, amount), sender => removeMemory(sender.source, sender.amount));
return new NativeMemoryLease((source, amount), static sender => removeMemory(sender.source, sender.amount));
}
/// <summary>
@@ -42,7 +43,7 @@ namespace osu.Framework.Platform
/// </summary>
public class NativeMemoryLease : InvokeOnDisposal<(object source, long amount)>
{
internal NativeMemoryLease((object source, long amount) sender, Action<(object source, long amount)> action)
internal NativeMemoryLease((object source, long amount) sender, [RequireStaticDelegate(IsError = true)] Action<(object source, long amount)> action)
: base(sender, action)
{
}