Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24102] Windows: Native method resolution and casting

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-12-20T17:24:19.000+0000
Affected Version/sRelease 5.4.0
Fix Version/sRelease 6.1.0
ComponentsWindows
Labelsn/a
ReporterKota Iguchi
AssigneeKota Iguchi
Created2016-11-04T06:46:50.000+0000
Updated2017-03-02T23:25:29.000+0000

Description

If a class has overloads for a method (multiple forms of the method with different signatures, but the same name), we need to attempt to match the correct method to invoke on the C# side by matching the passed in arguments to the closest match. Typically, this involves matching the name, number of arguments and the ability to convert the passed in arguments (in-order) to the method’s parameter types. We might want to slightly more liberal in accepting numeric primitives than typical method resolution due to the conversion of JS Numbers. Also, sometimes interfaces define generic return types such as Object and you will need to cast them to a different type to then reference methods and properties of the class. You can pass along the object you want to wrap to the constructor of the type you want to wrap it in.

Comments

  1. Kota Iguchi 2016-12-15

    https://github.com/appcelerator/hyperloop.next/pull/112
  2. Abir Mukherjee 2017-03-02

    Environment: NPM Version: 2.15.9 Node Version: 4.6.0 Windows OS: 10.0.14393.693 Appc CLI: 6.1.0 Appc CLI NPM: 4.2.8 Titanium SDK version: 6.1.0.v20170227120704 Appcelerator Studio, build: 4.8.1.201612050850 Windows Device: 8.1 and 10.0.14393 Windows Emulator 8.1 and 10.0.14393 I tested the demo apps, and validated the fix. There were two pull requests for this ticket; I tested with the demo apps from both PR's.
       var win = Ti.UI.createWindow({ backgroundColor: 'green' });
       win.addEventListener('open', function () {
       
           var Button = require('Windows.UI.Xaml.Controls.Button');
           var button = new Button();
       
           // Set JavaScript string for System.Object property
           button.Content = "PUSH PUSH";
       
           // No need to require TappedRoutedEventArgs for now in order to handle events
           button.addEventListener('Tapped', function (e) {
               // button.Content should be a System.Object
               Ti.API.info(button.Content.ToString());
       
               // Cast System.Object to System.String and then call String methods
               var content_str = require('System.String').cast(button.Content);
               Ti.API.info('button.Content length = ' + content_str.Length);
               alert('This should be true: ' + content_str.EndsWith(' PUSH'));
           });
       
           win.add(button);
       
           var System_Math = require('System.Math');
       
           // Call System.Math.Abs(double); (implicit)
           Ti.API.info(System_Math.Abs(-1.23));
       
           // Call System.Math.Abs(double); (explicit)
           Ti.API.info(System_Math.Abs(require('System.Double').cast(-1.23)));
       
           // Call System.Math.Abs(Int32);
           Ti.API.info(System_Math.Abs(require('System.Int32').cast(-1.23)));
       });
       win.open();
       
       require('Windows.UI.Xaml.Input.TappedRoutedEventArgs');
       require('Windows.UI.Xaml.Input.TappedRoutedEventArgs');
       
       var win = Ti.UI.createWindow({ backgroundColor: 'green' }),
           Button = require('Windows.UI.Xaml.Controls.Button'),
           button = new Button();
       
       button.Content = "PUSH";
       button.addEventListener('Tapped', function (e) {
           alert('Tapped');
       });
       button.addEventListener('Tapped', function (e) {
           Ti.API.info('This should not cause compile error');
       });
       
       win.add(button);
       win.open();
       

JSON Source