From 5a92b02fde5bc8428b6a04a6277faa0bf9875d20 Mon Sep 17 00:00:00 2001 From: badcel <1218031+badcel@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:07:19 +0100 Subject: [PATCH] Interfaces should implement IDisposable Interfaces can only be implemented by GObject classes not records. Every class inherits from GObject.Object which implements IDisposable. So implementing IDisposable on interfaces is possible. In case of GirCore every instance of an object has a native counterpart. As the dotnet runtime does not know how big this native counterpart is the user should be able to explicitly dispose all instances which is easier if IDisposable is available on interfaces. Fixes: #1202 --- .../Renderer/Public/Interface/InterfaceMethods.cs | 2 +- .../GObject-2.0.Tests/Classes/InterfaceTests.cs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/Tests/Libs/GObject-2.0.Tests/Classes/InterfaceTests.cs diff --git a/src/Generation/Generator/Renderer/Public/Interface/InterfaceMethods.cs b/src/Generation/Generator/Renderer/Public/Interface/InterfaceMethods.cs index 26f18a33c..0c1a07ccc 100644 --- a/src/Generation/Generator/Renderer/Public/Interface/InterfaceMethods.cs +++ b/src/Generation/Generator/Renderer/Public/Interface/InterfaceMethods.cs @@ -20,7 +20,7 @@ namespace {Namespace.GetPublicName(iface.Namespace)}; // AUTOGENERATED FILE - DO NOT MODIFY -public partial interface {iface.Name} +public partial interface {iface.Name} : IDisposable {{ {iface.Methods .Where(Method.IsEnabled) diff --git a/src/Tests/Libs/GObject-2.0.Tests/Classes/InterfaceTests.cs b/src/Tests/Libs/GObject-2.0.Tests/Classes/InterfaceTests.cs new file mode 100644 index 000000000..0e90b6e43 --- /dev/null +++ b/src/Tests/Libs/GObject-2.0.Tests/Classes/InterfaceTests.cs @@ -0,0 +1,15 @@ +using System; +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace GObject.Tests.Classes; + +[TestClass, TestCategory("UnitTest")] +public class InterfaceTests : Test +{ + [TestMethod] + public void InterfaceShouldImplementIDisposable() + { + typeof(TypePlugin).Should().Implement(); + } +}