From 6c6756172a589552020c1c7c2e76ba0a60e95252 Mon Sep 17 00:00:00 2001 From: badcel <1218031+badcel@users.noreply.github.com> Date: Tue, 11 Feb 2025 21:58:54 +0100 Subject: [PATCH] GObject.Object: Make "Dispose" method virtual again The virtual keyword got lost by accident during the implementation of the new instantiation framework. Custom classes want to be able to plug into the "Dispose" call of GObject.Object otherwise the custom "Dispose" would eventually not be executed if the method is marked with the "new" keyword. --- src/Libs/GObject-2.0/Public/Object.cs | 2 +- src/Tests/Libs/GirTest-0.1.Tests/ClassTest.cs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Libs/GObject-2.0/Public/Object.cs b/src/Libs/GObject-2.0/Public/Object.cs index 7b9d19dd6..5f3edc678 100644 --- a/src/Libs/GObject-2.0/Public/Object.cs +++ b/src/Libs/GObject-2.0/Public/Object.cs @@ -16,7 +16,7 @@ protected Object(ObjectHandle handle) Handle.AddMemoryPressure(); } - public void Dispose() + public virtual void Dispose() { Debug.WriteLine($"Handle {Handle.DangerousGetHandle()}: Disposing object of type {GetType()}."); DisposeClosures(); diff --git a/src/Tests/Libs/GirTest-0.1.Tests/ClassTest.cs b/src/Tests/Libs/GirTest-0.1.Tests/ClassTest.cs index cec4b6ed3..cb9764158 100644 --- a/src/Tests/Libs/GirTest-0.1.Tests/ClassTest.cs +++ b/src/Tests/Libs/GirTest-0.1.Tests/ClassTest.cs @@ -62,6 +62,12 @@ public void CanTransferOwnershipOfInterfaces() instanceData.RefCount.Should().Be(1); } + [TestMethod] + public void GObjectDisposeMethodIsVirtual() + { + typeof(GObject.Object).GetMethod(nameof(GObject.Object.Dispose)).Should().BeVirtual(); + } + [TestMethod] public void TestManualGObjectDisposal() {