mirror of
https://github.com/godotengine/godot
synced 2024-09-16 02:27:37 +00:00
Merge pull request #65905 from raulsntos/dotnet/marshaling-collections
C#: Fix marshaling generic Godot collections
This commit is contained in:
commit
5826e96014
|
@ -474,6 +474,11 @@ namespace Godot.Collections
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal interface IGenericGodotArray
|
||||||
|
{
|
||||||
|
public Array UnderlyingArray { get; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Typed wrapper around Godot's Array class, an array of Variant
|
/// Typed wrapper around Godot's Array class, an array of Variant
|
||||||
/// typed elements allocated in the engine in C++. Useful when
|
/// typed elements allocated in the engine in C++. Useful when
|
||||||
|
@ -487,7 +492,8 @@ namespace Godot.Collections
|
||||||
IList<T>,
|
IList<T>,
|
||||||
IReadOnlyList<T>,
|
IReadOnlyList<T>,
|
||||||
ICollection<T>,
|
ICollection<T>,
|
||||||
IEnumerable<T>
|
IEnumerable<T>,
|
||||||
|
IGenericGodotArray
|
||||||
{
|
{
|
||||||
private static godot_variant ToVariantFunc(in Array<T> godotArray) =>
|
private static godot_variant ToVariantFunc(in Array<T> godotArray) =>
|
||||||
VariantUtils.CreateFromArray(godotArray);
|
VariantUtils.CreateFromArray(godotArray);
|
||||||
|
@ -503,6 +509,8 @@ namespace Godot.Collections
|
||||||
|
|
||||||
private readonly Array _underlyingArray;
|
private readonly Array _underlyingArray;
|
||||||
|
|
||||||
|
Array IGenericGodotArray.UnderlyingArray => _underlyingArray;
|
||||||
|
|
||||||
internal ref godot_array.movable NativeValue
|
internal ref godot_array.movable NativeValue
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|
|
@ -344,6 +344,11 @@ namespace Godot.Collections
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal interface IGenericGodotDictionary
|
||||||
|
{
|
||||||
|
public Dictionary UnderlyingDictionary { get; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Typed wrapper around Godot's Dictionary class, a dictionary of Variant
|
/// Typed wrapper around Godot's Dictionary class, a dictionary of Variant
|
||||||
/// typed elements allocated in the engine in C++. Useful when
|
/// 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>
|
/// <typeparam name="TValue">The type of the dictionary's values.</typeparam>
|
||||||
public class Dictionary<[MustBeVariant] TKey, [MustBeVariant] TValue> :
|
public class Dictionary<[MustBeVariant] TKey, [MustBeVariant] TValue> :
|
||||||
IDictionary<TKey, TValue>,
|
IDictionary<TKey, TValue>,
|
||||||
IReadOnlyDictionary<TKey, TValue>
|
IReadOnlyDictionary<TKey, TValue>,
|
||||||
|
IGenericGodotDictionary
|
||||||
{
|
{
|
||||||
private static godot_variant ToVariantFunc(in Dictionary<TKey, TValue> godotDictionary) =>
|
private static godot_variant ToVariantFunc(in Dictionary<TKey, TValue> godotDictionary) =>
|
||||||
VariantUtils.CreateFromDictionary(godotDictionary);
|
VariantUtils.CreateFromDictionary(godotDictionary);
|
||||||
|
@ -370,6 +376,8 @@ namespace Godot.Collections
|
||||||
|
|
||||||
private readonly Dictionary _underlyingDict;
|
private readonly Dictionary _underlyingDict;
|
||||||
|
|
||||||
|
Dictionary IGenericGodotDictionary.UnderlyingDictionary => _underlyingDict;
|
||||||
|
|
||||||
internal ref godot_dictionary.movable NativeValue
|
internal ref godot_dictionary.movable NativeValue
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|
|
@ -293,6 +293,10 @@ namespace Godot.NativeInterop
|
||||||
return VariantUtils.CreateFromDictionary(godotDictionary);
|
return VariantUtils.CreateFromDictionary(godotDictionary);
|
||||||
case Collections.Array godotArray:
|
case Collections.Array godotArray:
|
||||||
return VariantUtils.CreateFromArray(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:
|
case Variant variant:
|
||||||
return NativeFuncs.godotsharp_variant_new_copy((godot_variant)variant.NativeVar);
|
return NativeFuncs.godotsharp_variant_new_copy((godot_variant)variant.NativeVar);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue