aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-12-27 20:07:11 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2018-12-27 20:07:11 -0300
commit6940c3cb8c053e304d9d788848cf3540226930c7 (patch)
tree2c891593968f2828921e2843b74b1e073fb16395
parentefl-mono: Make Eina.Value.Set chainable. (diff)
downloadefl-devs/lauromoura/value_fixes.tar.gz
efl-csharp: Add implicit conversions for Eina.Valuedevs/lauromoura/value_fixes
For basic types, this will make it easier to pass Eina.Values into functions, without requiring to setup and later Set() values.
-rw-r--r--src/bindings/mono/eina_mono/eina_value.cs66
-rw-r--r--src/tests/efl_mono/ValueEolian.cs22
2 files changed, 88 insertions, 0 deletions
diff --git a/src/bindings/mono/eina_mono/eina_value.cs b/src/bindings/mono/eina_mono/eina_value.cs
index 567a51b023..22d1196e76 100644
--- a/src/bindings/mono/eina_mono/eina_value.cs
+++ b/src/bindings/mono/eina_mono/eina_value.cs
@@ -804,6 +804,72 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
return new Value(v);
}
+ /// <summary>Implicit conversion.</summary>
+ public static implicit operator Value(byte x)
+ {
+ return new Eina.Value(ValueType.Byte).Set(x);
+ }
+
+ /// <summary>Implicit conversion.</summary>
+ public static implicit operator Value(sbyte x)
+ {
+ return new Eina.Value(ValueType.SByte).Set(x);
+ }
+
+ /// <summary>Implicit conversion.</summary>
+ public static implicit operator Value(short x)
+ {
+ return new Eina.Value(ValueType.Short).Set(x);
+ }
+
+ /// <summary>Implicit conversion.</summary>
+ public static implicit operator Value(ushort x)
+ {
+ return new Eina.Value(ValueType.UShort).Set(x);
+ }
+
+ /// <summary>Implicit conversion.</summary>
+ public static implicit operator Value(int x)
+ {
+ return new Eina.Value(ValueType.Int32).Set(x);
+ }
+
+ /// <summary>Implicit conversion.</summary>
+ public static implicit operator Value(uint x)
+ {
+ return new Eina.Value(ValueType.UInt32).Set(x);
+ }
+
+ /// <summary>Implicit conversion.</summary>
+ public static implicit operator Value(long x)
+ {
+ return new Eina.Value(ValueType.Long).Set(x);
+ }
+
+ /// <summary>Implicit conversion.</summary>
+ public static implicit operator Value(ulong x)
+ {
+ return new Eina.Value(ValueType.ULong).Set(x);
+ }
+
+ /// <summary>Implicit conversion.</summary>
+ public static implicit operator Value(float x)
+ {
+ return new Eina.Value(ValueType.Float).Set(x);
+ }
+
+ /// <summary>Implicit conversion.</summary>
+ public static implicit operator Value(double x)
+ {
+ return new Eina.Value(ValueType.Double).Set(x);
+ }
+
+ /// <summary>Implicit conversion.</summary>
+ public static implicit operator Value(string x)
+ {
+ return new Eina.Value(ValueType.String).Set(x);
+ }
+
/// <summary>Creates an Value instance from a given array description.</summary>
private static Value FromArrayDesc(Eina.EinaNative.Value_Array arrayDesc)
{
diff --git a/src/tests/efl_mono/ValueEolian.cs b/src/tests/efl_mono/ValueEolian.cs
index 78da29087a..5f5d465387 100644
--- a/src/tests/efl_mono/ValueEolian.cs
+++ b/src/tests/efl_mono/ValueEolian.cs
@@ -116,6 +116,28 @@ public static class TestEinaValueEolian {
Test.AssertEquals(val, obj.value);
}
}
+
+ public static void TestEolianEinaValueImplicitOperators()
+ {
+ var obj = new Dummy.TestObject();
+ int payload = 1999;
+ obj.SetValue(payload);
+
+ var expected = new Eina.Value(1999);
+ var received = new Eina.Value(Eina.ValueType.String);
+
+ obj.OutValue(out received);
+ Test.AssertEquals(expected, received);
+ Test.AssertEquals(Eina.ValueType.Int32, received.GetValueType());
+
+ expected = new Eina.Value("Hallo");
+ obj.SetValue("Hallo");
+
+ obj.OutValue(out received);
+ Test.AssertEquals(expected, received);
+ Test.AssertEquals(Eina.ValueType.String, received.GetValueType());
+
+ }
}
#pragma warning restore 1591
}