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); } }
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); }
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(); }
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(); }
public virtual void CallMethodWithJsValue(INetJsValue value, INetJsValue method) { method.Call(value); }
public void Test(INetJsValue jsValue) { Console.WriteLine("In net method, invoking callback"); jsValue.Call(); }