// 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 public partial class MouseButton: IDisposable { private unsafe Raw.MouseButton* _inner; /// /// Creates a managed MouseButton 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 MouseButton(Raw.MouseButton* handle) { _inner = handle; } /// /// A MouseButton allocated on Rust side. /// public static MouseButton New(MouseButtonType button) { unsafe { Raw.MouseButtonType buttonRaw; buttonRaw = (Raw.MouseButtonType)button; Raw.MouseButton* retVal = Raw.MouseButton.New(buttonRaw); return new MouseButton(retVal); } } /// /// A Operation allocated on Rust side. /// public Operation AsOperationMouseButtonPressed() { unsafe { if (_inner == null) { throw new ObjectDisposedException("MouseButton"); } Raw.Operation* retVal = Raw.MouseButton.AsOperationMouseButtonPressed(_inner); return new Operation(retVal); } } /// /// A Operation allocated on Rust side. /// public Operation AsOperationMouseButtonReleased() { unsafe { if (_inner == null) { throw new ObjectDisposedException("MouseButton"); } Raw.Operation* retVal = Raw.MouseButton.AsOperationMouseButtonReleased(_inner); return new Operation(retVal); } } /// /// Returns the underlying raw handle. /// public unsafe Raw.MouseButton* AsFFI() { return _inner; } /// /// Destroys the underlying object immediately. /// public void Dispose() { unsafe { if (_inner == null) { return; } Raw.MouseButton.Destroy(_inner); _inner = null; GC.SuppressFinalize(this); } } ~MouseButton() { Dispose(); } }