From 8e992e8b8e3a4656f539d8b456d928e5a6d15ac4 Mon Sep 17 00:00:00 2001 From: badcel <1218031+badcel@users.noreply.github.com> Date: Mon, 27 Nov 2023 11:05:14 +0100 Subject: [PATCH] GValue: Support setting a string array --- src/Libs/GObject-2.0/Public/Type.cs | 1 + src/Libs/GObject-2.0/Public/Value.cs | 1 + src/Tests/Libs/GObject-2.0.Tests/Records/ValueTest.cs | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/src/Libs/GObject-2.0/Public/Type.cs b/src/Libs/GObject-2.0/Public/Type.cs index bc3ee718b..4fa244c8b 100644 --- a/src/Libs/GObject-2.0/Public/Type.cs +++ b/src/Libs/GObject-2.0/Public/Type.cs @@ -28,6 +28,7 @@ public partial struct Type public static readonly Type Param = new Type((nuint) Internal.BasicType.Param); public static readonly Type Object = new Type((nuint) Internal.BasicType.Object); public static readonly Type Variant = new Type((nuint) Internal.BasicType.Variant); + public static readonly Type StringArray = new Type((nuint) Internal.Functions.StrvGetType()); #endregion Statics diff --git a/src/Libs/GObject-2.0/Public/Value.cs b/src/Libs/GObject-2.0/Public/Value.cs index 6daa72eac..5aff22c29 100644 --- a/src/Libs/GObject-2.0/Public/Value.cs +++ b/src/Libs/GObject-2.0/Public/Value.cs @@ -30,6 +30,7 @@ public Value(Type type) public Value(double value) : this(Type.Double) => SetDouble(value); public Value(float value) : this(Type.Float) => SetFloat(value); public Value(string value) : this(Type.String) => SetString(value); + public Value(string[] value) : this(Type.StringArray) => SetBoxed(Utf8StringArrayNullTerminatedOwnedHandle.Create(value).DangerousGetHandle()); #endregion diff --git a/src/Tests/Libs/GObject-2.0.Tests/Records/ValueTest.cs b/src/Tests/Libs/GObject-2.0.Tests/Records/ValueTest.cs index 3eab69dea..bec13e5f1 100644 --- a/src/Tests/Libs/GObject-2.0.Tests/Records/ValueTest.cs +++ b/src/Tests/Libs/GObject-2.0.Tests/Records/ValueTest.cs @@ -47,6 +47,16 @@ public void ValueContainsExpectedBasicType(object data, Internal.BasicType basic Internal.Functions.TypeCheckValueHolds(v.Handle, (nuint) basicType).Should().BeTrue(); } + [TestMethod] + public void CanSetStringArry() + { + var array = new[] { "A", "B", "C" }; + var v = new Value(array); + + var result = v.Extract(); + result.Should().ContainInOrder(array); + } + [TestMethod] public void DisposeShouldFreeUnmanagedMemory() {