// by Diplomat #pragma warning disable 0105 using System; using System.Runtime.InteropServices; using Devolutions.IronRdp.Diplomat; #pragma warning restore 0105 namespace Devolutions.IronRdp; #nullable enable /// /// Stringified Picky error along with an error kind. /// public partial class IronRdpError: IDisposable { private unsafe Raw.IronRdpError* _inner; public IronRdpErrorKind Kind { get { return GetKind(); } } /// /// Creates a managed IronRdpError from a raw handle. /// /// /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
public unsafe IronRdpError(Raw.IronRdpError* handle) { _inner = handle; } /// /// Returns the error as a string. /// public void ToDisplay(DiplomatWriteable writeable) { unsafe { if (_inner == null) { throw new ObjectDisposedException("IronRdpError"); } Raw.IronRdpError.ToDisplay(_inner, &writeable); } } /// /// Returns the error as a string. /// public string ToDisplay() { unsafe { if (_inner == null) { throw new ObjectDisposedException("IronRdpError"); } DiplomatWriteable writeable = new DiplomatWriteable(); Raw.IronRdpError.ToDisplay(_inner, &writeable); string retVal = writeable.ToUnicode(); writeable.Dispose(); return retVal; } } /// /// Returns the error kind. /// /// /// A IronRdpErrorKind allocated on C# side. /// public IronRdpErrorKind GetKind() { unsafe { if (_inner == null) { throw new ObjectDisposedException("IronRdpError"); } Raw.IronRdpErrorKind retVal = Raw.IronRdpError.GetKind(_inner); return (IronRdpErrorKind)retVal; } } /// /// Returns the underlying raw handle. /// public unsafe Raw.IronRdpError* AsFFI() { return _inner; } /// /// Destroys the underlying object immediately. /// public void Dispose() { unsafe { if (_inner == null) { return; } Raw.IronRdpError.Destroy(_inner); _inner = null; GC.SuppressFinalize(this); } } ~IronRdpError() { Dispose(); } }