<PackageReference Include="System.Drawing.Common" Version="10.0.0-preview.3.25173.2" />

StatusExtensions

static class StatusExtensions
using System; using System.IO; using System.Private.Windows.Core.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Windows.Win32.Foundation; namespace Windows.Win32.Graphics.GdiPlus { internal static class StatusExtensions { internal static void ThrowIfFailed(this Status status) { if (status != 0) throw status.GetException(); } [NullableContext(1)] internal static Exception GetException(this Status status) { switch (status) { case Status.GenericError: return new ExternalException(SR.GdiplusGenericError, HRESULT.E_FAIL); case Status.InvalidParameter: return new ArgumentException(SR.GdiplusInvalidParameter); case Status.OutOfMemory: return new OutOfMemoryException(SR.GdiplusOutOfMemory); case Status.ObjectBusy: return new InvalidOperationException(SR.GdiplusObjectBusy); case Status.InsufficientBuffer: return new OutOfMemoryException(SR.GdiplusInsufficientBuffer); case Status.NotImplemented: return new NotImplementedException(SR.GdiplusNotImplemented); case Status.Win32Error: return new ExternalException(SR.GdiplusGenericError, HRESULT.E_FAIL); case Status.WrongState: return new InvalidOperationException(SR.GdiplusWrongState); case Status.Aborted: return new ExternalException(SR.GdiplusAborted, HRESULT.E_ABORT); case Status.FileNotFound: return new FileNotFoundException(SR.GdiplusFileNotFound); case Status.ValueOverflow: return new OverflowException(SR.GdiplusOverflow); case Status.AccessDenied: return new ExternalException(SR.GdiplusAccessDenied, HRESULT.E_ACCESSDENIED); case Status.UnknownImageFormat: return new ArgumentException(SR.GdiplusUnknownImageFormat); case Status.PropertyNotFound: return new ArgumentException(SR.GdiplusPropertyNotFoundError); case Status.PropertyNotSupported: return new ArgumentException(SR.GdiplusPropertyNotSupportedError); case Status.FontFamilyNotFound: return new ArgumentException(string.Format(SR.GdiplusFontFamilyNotFound, "?")); case Status.FontStyleNotFound: return new ArgumentException(string.Format(SR.GdiplusFontStyleNotFound, "?", "?")); case Status.NotTrueTypeFont: return new ArgumentException(SR.GdiplusNotTrueTypeFont_NoName); case Status.UnsupportedGdiplusVersion: return new ExternalException(SR.GdiplusUnsupportedGdiplusVersion, HRESULT.E_FAIL); case Status.GdiplusNotInitialized: return new ExternalException(SR.GdiplusNotInitialized, HRESULT.E_FAIL); default: { DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(3, 2); defaultInterpolatedStringHandler.AppendFormatted(SR.GdiplusUnknown); defaultInterpolatedStringHandler.AppendLiteral(" ["); defaultInterpolatedStringHandler.AppendFormatted(status); defaultInterpolatedStringHandler.AppendLiteral("]"); return new ExternalException(defaultInterpolatedStringHandler.ToStringAndClear(), HRESULT.E_UNEXPECTED); } } } } }