summaryrefslogtreecommitdiff
path: root/modules/mono/glue/GodotSharp
diff options
context:
space:
mode:
authorRaul Santos <raulsntos@gmail.com>2022-09-16 13:46:34 +0200
committerRaul Santos <raulsntos@gmail.com>2022-09-16 16:42:40 +0200
commit7535803023eb294918c58a5bd2134a1060bd9a0d (patch)
tree61a7fdac934b07547486824e7d1f7c8f2d6d6bc3 /modules/mono/glue/GodotSharp
parentc2babb65580d4dce3a0fc8834dd05fe177227b6e (diff)
C#: Fix marshaling generic Godot collections
Add support for generic Godot collections to `ConvertManagedObjectToVariant`.
Diffstat (limited to 'modules/mono/glue/GodotSharp')
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs10
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs10
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs4
3 files changed, 22 insertions, 2 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs
index 1c98dfcdf6..93a631c798 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs
@@ -474,6 +474,11 @@ namespace Godot.Collections
}
}
+ internal interface IGenericGodotArray
+ {
+ public Array UnderlyingArray { get; }
+ }
+
/// <summary>
/// Typed wrapper around Godot's Array class, an array of Variant
/// typed elements allocated in the engine in C++. Useful when
@@ -487,7 +492,8 @@ namespace Godot.Collections
IList<T>,
IReadOnlyList<T>,
ICollection<T>,
- IEnumerable<T>
+ IEnumerable<T>,
+ IGenericGodotArray
{
// ReSharper disable StaticMemberInGenericType
// Warning is about unique static fields being created for each generic type combination:
@@ -516,6 +522,8 @@ namespace Godot.Collections
private readonly Array _underlyingArray;
+ Array IGenericGodotArray.UnderlyingArray => _underlyingArray;
+
internal ref godot_array.movable NativeValue
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs
index 93103d0f6b..e00e4e85b7 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs
@@ -344,6 +344,11 @@ namespace Godot.Collections
}
}
+ internal interface IGenericGodotDictionary
+ {
+ public Dictionary UnderlyingDictionary { get; }
+ }
+
/// <summary>
/// Typed wrapper around Godot's Dictionary class, a dictionary of Variant
/// typed elements allocated in the engine in C++. Useful when
@@ -354,7 +359,8 @@ namespace Godot.Collections
/// <typeparam name="TValue">The type of the dictionary's values.</typeparam>
public class Dictionary<[MustBeVariant] TKey, [MustBeVariant] TValue> :
IDictionary<TKey, TValue>,
- IReadOnlyDictionary<TKey, TValue>
+ IReadOnlyDictionary<TKey, TValue>,
+ IGenericGodotDictionary
{
// ReSharper disable StaticMemberInGenericType
// Warning is about unique static fields being created for each generic type combination:
@@ -393,6 +399,8 @@ namespace Godot.Collections
private readonly Dictionary _underlyingDict;
+ Dictionary IGenericGodotDictionary.UnderlyingDictionary => _underlyingDict;
+
internal ref godot_dictionary.movable NativeValue
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs
index 140fc167ba..31a43d1cc9 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs
@@ -293,6 +293,10 @@ namespace Godot.NativeInterop
return VariantUtils.CreateFromDictionary(godotDictionary);
case Collections.Array godotArray:
return VariantUtils.CreateFromArray(godotArray);
+ case Collections.IGenericGodotDictionary godotDictionary:
+ return VariantUtils.CreateFromDictionary(godotDictionary.UnderlyingDictionary);
+ case Collections.IGenericGodotArray godotArray:
+ return VariantUtils.CreateFromArray(godotArray.UnderlyingArray);
case Variant variant:
return NativeFuncs.godotsharp_variant_new_copy((godot_variant)variant.NativeVar);
}