コード例 #1
0
        public static List <T> AsList <T>(this INetJsValue value)
        {
            if (value == null || !value.IsArray)
            {
                return(null);
            }

            if (typeof(T) != typeof(int) && typeof(T) != typeof(string))
            {
                // Only enumerables of int and string are currently supported
                return(null);
            }

            var list = new List <T>();

            try
            {
                var length = (int)value.GetProperty("length");

                for (var i = 0; i < length; i++)
                {
                    var item = value.GetItemAtIndex(i);
                    list.Add((T)item);
                }

                return(list);
            }
            catch
            {
                return(null);
            }
        }
コード例 #2
0
        public static List <T> AsList <T>(this INetJsValue value)
        {
            if (value == null || !value.IsArray)
            {
                return(null);
            }

            if (typeof(T) != typeof(int) && typeof(T) != typeof(string))
            {
                // Only enumerables of int and string are currently supported
                return(null);
            }

            var destinationConverter = TypeDescriptor.GetConverter(typeof(T));

            var list = new List <T>();

            var length = (int)value.GetProperty("length");

            for (var i = 0; i < length; i++)
            {
                var item = value.GetItemAtIndex(i);
                if (item is T casted)
                {
                    list.Add(casted);
                }
                else
                {
                    list.Add((T)destinationConverter.ConvertFrom(null, CultureInfo.InvariantCulture, item));
                }
            }

            return(list);
        }
コード例 #3
0
ファイル: JsValueTests.cs プロジェクト: moialbla/Qml.Net
        public void Can_send_non_function()
        {
            INetJsValue jsValue = null;

            Mock.Setup(x => x.Method(It.IsAny <INetJsValue>()))
            .Callback(new Action <dynamic>(x =>
            {
                jsValue = x;
            }));

            NetTestHelper.RunQml(qmlApplicationEngine,
                                 @"
                    import QtQuick 2.0
                    import tests 1.0
                    JsTestsQml {
                        id: test
                        Component.onCompleted: function() {
                            test.method({})
                        }
                    }
                ");

            Mock.Verify(x => x.Method(It.IsAny <INetJsValue>()), Times.Once);
            jsValue.Should().NotBeNull();
            jsValue.IsCallable.Should().BeFalse();
        }
コード例 #4
0
ファイル: JsValueTests.cs プロジェクト: zhangbo27/qmlnet
        public void Can_send_function()
        {
            INetJsValue jsValue = null;

            Mock.Setup(x => x.Method(It.IsAny <INetJsValue>()))
            .Callback(new Action <dynamic>(x => jsValue = x));

            RunQmlTest(
                "test",
                @"
                    test.method(function(){})
                ");

            Mock.Verify(x => x.Method(It.IsAny <INetJsValue>()), Times.Once);
            jsValue.Should().NotBeNull();
            jsValue.IsCallable.Should().BeTrue();
        }
コード例 #5
0
ファイル: JsValueTests.cs プロジェクト: zhangbo27/qmlnet
 public virtual void CallMethodWithJsValue(INetJsValue value, INetJsValue method)
 {
     method.Call(value);
 }
コード例 #6
0
ファイル: Program.UI.cs プロジェクト: moialbla/Qml.Net
 public void Test(INetJsValue jsValue)
 {
     Console.WriteLine("In net method, invoking callback");
     jsValue.Call();
 }