using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using TerraFX.Interop.Windows;
namespace ComputeSharp.D2D1.Tests.Extensions;
///
/// Helper methods to efficiently throw exceptions.
///
/// Trimmed down version of the same file in ComputeSharp.
[DebuggerStepThrough]
internal static class HResultExtensions
{
///
/// Throws a if represents an error.
///
/// The input to check.
/// Thrown if represents an error.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Assert(this HRESULT result)
{
if ((int)result < 0)
{
ThrowWin32Exception(result);
}
}
///
/// Throws a if represents an error.
///
/// The input to check.
/// Thrown if represents an error.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Assert(this int result)
{
if (result < 0)
{
ThrowWin32Exception(result);
}
}
///
/// Throws a .
///
/// The input return code.
[DoesNotReturn]
private static void ThrowWin32Exception(int result)
{
throw new Win32Exception(result);
}
}