예제 #1
0
        public void WriteProperty(IntPtr p, IntPtr t, IntPtr ip, IntPtr v)
        {
            using (var property = new NetPropertyInfo(p))
                using (var target = new NetReference(t))
                    using (var indexParameter = ip != IntPtr.Zero ? new NetVariant(ip) : null)
                        using (var value = new NetVariant(v))
                        {
                            var o = target.Instance;

                            var propertInfo = o.GetType()
                                              .GetProperty(property.Name, BindingFlags.Instance | BindingFlags.Public);

                            if (propertInfo == null)
                            {
                                throw new InvalidOperationException($"Invalid property {property.Name}");
                            }

                            object newValue = null;
                            Helpers.Unpackvalue(ref newValue, value);

                            if (indexParameter != null)
                            {
                                object indexParameterValue = null;
                                Helpers.Unpackvalue(ref indexParameterValue, indexParameter);
                                propertInfo.SetValue(o, newValue, new[] { indexParameterValue });
                            }
                            else
                            {
                                propertInfo.SetValue(o, newValue);
                            }
                        }
        }
예제 #2
0
        private static IntPtr Create(List <string> args)
        {
            if (args == null)
            {
                args = new List <string>();
            }

            // By default, the argv[0] should be the process name.
            // .NET doesn't pass that name, but Qt should get it
            // since it does in a normal Qt environment.
            args.Insert(0, System.Diagnostics.Process.GetCurrentProcess().ProcessName);

            using (var strings = new NetVariantList())
            {
                foreach (var arg in args)
                {
                    using (var variant = new NetVariant())
                    {
                        variant.String = arg;
                        strings.Add(variant);
                    }
                }

                return(Interop.QGuiApplication.Create(strings.Handle, IntPtr.Zero));
            }
        }
예제 #3
0
        public override void InvokeMethod(NetMethodInfo methodInfo, NetInstance target, NetVariantVector parameters,
                                          NetVariant result)
        {
            var handle = (GCHandle)target.GetGCHandle();
            var o      = handle.Target;

            List <object> methodParameters = null;

            if (parameters.Count > 0)
            {
                methodParameters = new List <object>();
                foreach (var parameterInstance in parameters)
                {
                    object v = null;
                    Unpackvalue(ref v, parameterInstance);
                    methodParameters.Add(v);
                }
            }

            var r = o.GetType()
                    .GetMethod(methodInfo.GetMethodName(), BindingFlags.Instance | BindingFlags.Public)
                    .Invoke(o, methodParameters?.ToArray());

            if (result == null)
            {
                // this method doesn't have return type
            }
            else
            {
                PackValue(ref r, result);
            }
        }
예제 #4
0
        public static void Unpackvalue(ref object destination, NetVariant source)
        {
            switch (source.VariantType)
            {
            case NetVariantType.Invalid:
                destination = null;
                break;

            case NetVariantType.Bool:
                destination = source.Bool;
                break;

            case NetVariantType.Char:
                destination = source.Char;
                break;

            case NetVariantType.Int:
                destination = source.Int;
                break;

            case NetVariantType.UInt:
                destination = source.UInt;
                break;

            case NetVariantType.Long:
                destination = source.Long;
                break;

            case NetVariantType.ULong:
                destination = source.ULong;
                break;

            case NetVariantType.Float:
                destination = source.Float;
                break;

            case NetVariantType.Double:
                destination = source.Double;
                break;

            case NetVariantType.String:
                destination = source.String;
                break;

            case NetVariantType.DateTime:
                destination = source.DateTime;
                break;

            case NetVariantType.Object:
                destination = source.Instance.Instance;
                break;

            case NetVariantType.JsValue:
                destination = source.JsValue.AsDynamic();
                break;

            default:
                throw new Exception("Unsupported variant type.");
            }
        }
예제 #5
0
        public bool ActivateSignal(string signalName, params object[] parameters)
        {
            QmlNetConfig.EnsureUIThread();

            if (parameters != null && parameters.Length > 0)
            {
                using (var list = new NetVariantList())
                {
                    foreach (var parameter in parameters)
                    {
                        using (var variant = new NetVariant())
                        {
                            Helpers.PackValue(parameter, variant);
                            list.Add(variant);
                        }
                    }

                    return(Interop.NetReference.ActivateSignal(Handle, signalName, list.Handle) == 1);
                }
            }
            else
            {
                return(Interop.NetReference.ActivateSignal(Handle, signalName, IntPtr.Zero) == 1);
            }
        }
예제 #6
0
        public void WriteProperty(IntPtr p, IntPtr t, IntPtr ip, IntPtr v)
        {
            using (var property = new NetPropertyInfo(p))
                using (var target = new NetReference(t))
                    using (var indexParameter = ip != IntPtr.Zero ? new NetVariant(ip) : null)
                        using (var value = new NetVariant(v))
                        {
                            CodeGen.CodeGen.InvokeMethodDelegate del;
                            if (!_cachedSetProperties.TryGetValue(property.Id, out del))
                            {
                                del = CodeGen.CodeGen.BuildSetPropertyDelegate(property);
                                _cachedSetProperties[property.Id] = del;
                            }

                            using (var list = new NetVariantList())
                            {
                                if (indexParameter != null)
                                {
                                    list.Add(indexParameter);
                                }

                                list.Add(value);
                                Task resultTask = null;
                                del(target, list, null, ref resultTask);
                            }
                        }
        }
예제 #7
0
 private static object Obj(NetVariant variant)
 {
     using (var reference = variant.Instance)
     {
         return(reference?.Instance);
     }
 }
예제 #8
0
        public void Can_store_variant_list()
        {
            using (var variant = new NetVariant())
                using (var variantList = new NetVariantList())
                {
                    using (var value1 = NetVariant.From(3))
                    {
                        variantList.Add(value1);
                    }

                    variant.VariantType.Should().Be(NetVariantType.Invalid);
                    variant.NetVariantList = variantList;
                    variant.VariantType.Should().Be(NetVariantType.NetVariantList);

                    using (var resultVariantList = variant.NetVariantList)
                    {
                        resultVariantList.Should().NotBeNull();
                        resultVariantList.Count.Should().Be(variantList.Count);
                        using (var value1 = resultVariantList.Get(0))
                            using (var value2 = variantList.Get(0))
                            {
                                value1.Int.Should().Be(3);
                                value2.Int.Should().Be(3);
                            }
                    }
                }
        }
예제 #9
0
        public void Can_get_property()
        {
            try
            {
                var value = new TestObject();
                value.TestProperty = "value1";

                var typeInfo = NetTypeManager.GetTypeInfo <TestObject>();
                typeInfo.EnsureLoaded();

                var readProperty =
                    global::Qml.Net.Internal.CodeGen.CodeGen.BuildReadPropertyDelegate(typeInfo.GetProperty(0));

                NetVariant result     = new NetVariant();
                Task       taskResult = null;
                readProperty(NetReference.CreateForObject(value), new NetVariantList(), result, ref taskResult);

                result.String.Should().Be("value1");

                throw new Exception("This shouldn't be ran");
            }
            catch (Exception ex)
            {
                ex.Message.Should().StartWith("Can't operate on struct types yet");
            }
        }
예제 #10
0
 public static void PackValue(object source, NetVariant destination)
 {
     if (source == null)
     {
         destination.Clear();
     }
     else
     {
         var type = source.GetType();
         if (type == typeof(bool))
         {
             destination.Bool = (bool)source;
         }
         else if (type == typeof(char))
         {
             destination.Char = (char)source;
         }
         else if (type == typeof(float))
         {
             destination.Float = (float)source;
         }
         else if (type == typeof(double))
         {
             destination.Double = (double)source;
         }
         else if (type == typeof(int))
         {
             destination.Int = (int)source;
         }
         else if (type == typeof(uint))
         {
             destination.UInt = (uint)source;
         }
         else if (type == typeof(long))
         {
             destination.Long = (long)source;
         }
         else if (type == typeof(ulong))
         {
             destination.ULong = (ulong)source;
         }
         else if (type == typeof(string))
         {
             destination.String = (string)source;
         }
         else if (type == typeof(DateTimeOffset))
         {
             destination.DateTime = ((DateTimeOffset)source).DateTime;
         }
         else if (typeof(INetJsValue).IsAssignableFrom(type))
         {
             destination.JsValue = ((NetJsValue.NetJsValueDynamic)source).JsValue;
         }
         else
         {
             destination.Instance = NetReference.CreateForObject(source);
         }
     }
 }
예제 #11
0
 private static void LoadObject(NetVariant variant, object value)
 {
     if (value != null)
     {
         if (value is bool valueBool)
         {
             variant.Bool = valueBool;
         }
         else if (value is char valueChar)
         {
             variant.Char = valueChar;
         }
         else if (value is int valueInt)
         {
             variant.Int = valueInt;
         }
         else if (value is uint valueUInt)
         {
             variant.UInt = valueUInt;
         }
         else if (value is long valueLong)
         {
             variant.Long = valueLong;
         }
         else if (value is ulong valueULong)
         {
             variant.ULong = valueULong;
         }
         else if (value is float valueFloat)
         {
             variant.Float = valueFloat;
         }
         else if (value is double valueDouble)
         {
             variant.Double = valueDouble;
         }
         else if (value is string valueString)
         {
             variant.String = valueString;
         }
         else if (value is DateTimeOffset valueDateTimeOffset)
         {
             variant.DateTime = valueDateTimeOffset;
         }
         else if (value is NetJsValue valueJsValue)
         {
             variant.JsValue = valueJsValue;
         }
         else
         {
             variant.Instance = NetReference.CreateForObject(value);
         }
     }
     else
     {
         variant.Clear();
     }
 }
예제 #12
0
            private static ulong?ULongNullable(NetVariant variant)
            {
                if (variant.VariantType == NetVariantType.Invalid)
                {
                    return(null);
                }

                return(variant.ULong);
            }
예제 #13
0
            private static uint?UIntNullable(NetVariant variant)
            {
                if (variant.VariantType == NetVariantType.Invalid)
                {
                    return(null);
                }

                return(variant.UInt);
            }
예제 #14
0
            private static double?DoubleNullable(NetVariant variant)
            {
                if (variant.VariantType == NetVariantType.Invalid)
                {
                    return(null);
                }

                return(variant.Double);
            }
예제 #15
0
            private static bool?BoolNullable(NetVariant variant)
            {
                if (variant.VariantType == NetVariantType.Invalid)
                {
                    return(null);
                }

                return(variant.Bool);
            }
예제 #16
0
            private static char?CharNullable(NetVariant variant)
            {
                if (variant.VariantType == NetVariantType.Invalid)
                {
                    return(null);
                }

                return(variant.Char);
            }
예제 #17
0
        public void Can_clear_value()
        {
            var variant = new NetVariant();

            variant.String = "test";
            variant.VariantType.Should().Be(NetVariantType.String);
            variant.Clear();
            variant.VariantType.Should().Be(NetVariantType.Invalid);
        }
예제 #18
0
 public void Can_store_null()
 {
     using (var variant = new NetVariant())
     {
         variant.VariantType.Should().Be(NetVariantType.Invalid);
         variant.SetNull();
         variant.VariantType.Should().Be(NetVariantType.Null);
     }
 }
예제 #19
0
            private static float?FloatNullable(NetVariant variant)
            {
                if (variant.VariantType == NetVariantType.Invalid)
                {
                    return(null);
                }

                return(variant.Float);
            }
예제 #20
0
        public void Can_store_double()
        {
            var variant = new NetVariant();

            variant.Double = double.MinValue;
            variant.VariantType.Should().Be(NetVariantType.Double);
            variant.Double.Should().Be(double.MinValue);
            variant.Double = double.MaxValue;
            variant.Double.Should().Be(double.MaxValue);
        }
예제 #21
0
        public void Can_store_bool()
        {
            var variant = new NetVariant();

            variant.Bool = true;
            variant.VariantType.Should().Be(NetVariantType.Bool);
            variant.Bool.Should().BeTrue();
            variant.Bool = false;
            variant.Bool.Should().BeFalse();
        }
예제 #22
0
        public void Can_store_long()
        {
            var variant = new NetVariant();

            variant.Long = -1;
            variant.VariantType.Should().Be(NetVariantType.Long);
            variant.Long.Should().Be(-1);
            variant.Long = long.MaxValue;
            variant.Long.Should().Be(long.MaxValue);
        }
예제 #23
0
        public void Can_store_uint()
        {
            var variant = new NetVariant();

            variant.UInt = uint.MinValue;
            variant.VariantType.Should().Be(NetVariantType.UInt);
            variant.UInt.Should().Be(uint.MinValue);
            variant.UInt = uint.MaxValue;
            variant.UInt.Should().Be(uint.MaxValue);
        }
예제 #24
0
        public void Can_store_int()
        {
            var variant = new NetVariant();

            variant.Int = -1;
            variant.VariantType.Should().Be(NetVariantType.Int);
            variant.Int.Should().Be(-1);
            variant.Int = int.MaxValue;
            variant.Int.Should().Be(int.MaxValue);
        }
예제 #25
0
        public void Can_store_char()
        {
            var variant = new NetVariant();

            variant.Char = 'Ώ';
            variant.VariantType.Should().Be(NetVariantType.Char);
            variant.Char.Should().Be('Ώ');
            variant.Char = ' ';
            variant.Char.Should().Be(' ');
        }
예제 #26
0
        public void Can_store_ulong()
        {
            var variant = new NetVariant();

            variant.ULong = ulong.MinValue;
            variant.VariantType.Should().Be(NetVariantType.ULong);
            variant.ULong.Should().Be(ulong.MinValue);
            variant.ULong = ulong.MaxValue;
            variant.ULong.Should().Be(ulong.MaxValue);
        }
예제 #27
0
        public void Can_store_float()
        {
            var variant = new NetVariant();

            variant.Float = float.MinValue;
            variant.VariantType.Should().Be(NetVariantType.Float);
            variant.Float.Should().Be(float.MinValue);
            variant.Float = float.MaxValue;
            variant.Float.Should().Be(float.MaxValue);
        }
예제 #28
0
 private static void LoadBoolNullable(NetVariant variant, bool?value)
 {
     if (value.HasValue)
     {
         variant.Bool = value.Value;
     }
     else
     {
         variant.Clear();
     }
 }
예제 #29
0
 private static void LoadUIntNullable(NetVariant variant, uint?value)
 {
     if (value.HasValue)
     {
         variant.UInt = value.Value;
     }
     else
     {
         variant.Clear();
     }
 }
예제 #30
0
 private static void LoadCharNullable(NetVariant variant, char?value)
 {
     if (value.HasValue)
     {
         variant.Char = value.Value;
     }
     else
     {
         variant.Clear();
     }
 }