From 99260d972f2459cd26509db405565904a7573648 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Mon, 31 Oct 2022 13:42:26 +0100 Subject: C#: Add implicit conversion from arrays to Variant Adds an implicit conversion from supported array types (the ones that are equivalent to `Packed*Array` types in Godot) to Variant. --- modules/mono/glue/GodotSharp/GodotSharp/Variant.cs | 56 ++++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Variant.cs b/modules/mono/glue/GodotSharp/GodotSharp/Variant.cs index 1f37694995..d354509dbf 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Variant.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Variant.cs @@ -765,6 +765,58 @@ public partial struct Variant : IDisposable public static implicit operator Variant(SignalInfo from) => CreateTakingOwnershipOfDisposableValue(VariantUtils.CreateFromSignalInfo(from)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(byte[] from) => + (Variant)from.AsSpan(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(int[] from) => + (Variant)from.AsSpan(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(long[] from) => + (Variant)from.AsSpan(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(float[] from) => + (Variant)from.AsSpan(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(double[] from) => + (Variant)from.AsSpan(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(string[] from) => + (Variant)from.AsSpan(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(Vector2[] from) => + (Variant)from.AsSpan(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(Vector3[] from) => + (Variant)from.AsSpan(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(Color[] from) => + (Variant)from.AsSpan(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(Godot.Object[] from) => + CreateTakingOwnershipOfDisposableValue(VariantUtils.CreateFromSystemArrayOfGodotObject(from)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(StringName[] from) => + (Variant)from.AsSpan(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(NodePath[] from) => + (Variant)from.AsSpan(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(RID[] from) => + (Variant)from.AsSpan(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator Variant(Span from) => CreateTakingOwnershipOfDisposableValue(VariantUtils.CreateFromPackedByteArray(from)); @@ -801,10 +853,6 @@ public partial struct Variant : IDisposable public static implicit operator Variant(Span from) => CreateTakingOwnershipOfDisposableValue(VariantUtils.CreateFromPackedColorArray(from)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator Variant(Godot.Object[] from) => - CreateTakingOwnershipOfDisposableValue(VariantUtils.CreateFromSystemArrayOfGodotObject(from)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator Variant(Span from) => CreateTakingOwnershipOfDisposableValue(VariantUtils.CreateFromSystemArrayOfStringName(from)); -- cgit v1.2.3