static Task InvokeAction(object action, object[] args)
        {
            MethodInfo invokeMethod = action.GetType().GetMethod("Invoke");

            ParameterInfo[] invokeMethodParms = invokeMethod.GetParameters();

            //the JS args should be aligned with invokeMethodParms.Length - how to make default values?
            if (args.Length != invokeMethodParms.Length)
            {
                throw new IndexOutOfRangeException("JS parameters count doesn't equal WASM version.");
            }

            for (int a = 0; a < args.Length; a++)
            {
                object arg      = args[a];
                Type   parmType = invokeMethodParms[a].ParameterType;
                if ((typeof(EventArgs).IsAssignableFrom(parmType)) && (arg is NativeJsObject njo))
                {
                    args[a] = new NativeEventArgs(EventArgs.Empty, njo);
                }
                else if (parmType != typeof(object))
                {
                    args[a] = Convert.ChangeType(arg, parmType);
                }
            }

            invokeMethod.Invoke(action, args);
            return(Task.CompletedTask);
        }
Esempio n. 2
0
 void OnNameChangedEvent(NativeEventArgs args)
 {
     Toast.MakeText(
         this,
         $"Hi {args.Message}, from Android",
         ToastLength.Long
         ).Show();
 }
Esempio n. 3
0
        private void OnNameChangedEvent(NativeEventArgs args)
        {
            var alertView = new UIAlertView {
                Title   = "Native Alert",
                Message = $"Hi {args.Message}, from iOS"
            };

            alertView.AddButton("OK");
            alertView.Show();
        }
Esempio n. 4
0
 private async void OnNativeEvent(NativeEventArgs args)
 {
     var msg = new MessageDialog($"Hi {args.Message}, from Windows");
     await msg.ShowAsync();
 }
Esempio n. 5
0
 private void OnNameChangedEvent(NativeEventArgs args)
 {
     Toast.MakeText(this, args.Message, ToastLength.Long).Show();
 }