@@ -104,28 +104,37 @@ public bool TryCallMethod(long objectId, string name, object[] parameters, out o
104104
105105 try
106106 {
107- //Fix for C# paramArray and refactor on arguments mismatch 03/22 /2016
107+ //Added param array support. Current implementation support param Object only. 04/04 /2016
108108 var missingParams = method . ParameterCount - parameters . Length ;
109- if ( missingParams > 0 || method . MethodParameters . Any ( t => t . IsParamArray ) )
109+ //CONDITION #1 : Check for parameter count missmatch between the parameters on the javascript function and the
110+ // number of parameters on the bound object method.
111+ //CONDITION #2 : Check if the bound object method contains a ParamArray as the last parameter on the method signature.
112+ if ( missingParams > 0 || method . MethodParameters . LastOrDefault ( t => t . IsParamArray ) != null )
110113 {
111- var paramList = new List < object > ( ) ;
114+ var paramList = new List < object > ( method . MethodParameters . Count ) ;
112115
113- for ( int i = 0 ; i < method . MethodParameters . Count ; i ++ )
116+ //Loop through all of the method parameters on the bound object.
117+ for ( var i = 0 ; i < method . MethodParameters . Count ; i ++ )
114118 {
119+ //Attempt to get the javascript function param at the current bound object parameter index.
120+ //If the javascript function param is missing IE: NULL, then add Type.Missing.
121+ //This will allow for default bound object parameters. IE: (string someParameter = "someValue")
115122 object jsParam = parameters . ElementAtOrDefault ( i ) ;
116123 if ( jsParam == null && ! method . MethodParameters [ i ] . IsParamArray )
117124 {
118125 paramList . Add ( Type . Missing ) ;
119126 }
127+ //If the method parameter is a paramArray IE: (params Object[] someParameter)
128+ //grab the parameters from the javascript function starting at the current bound object parameter index
129+ //and add create an array that will be passed in as the last bound object method parameter.
120130 else if ( method . MethodParameters [ i ] . IsParamArray )
121131 {
122132 List < object > convertedParams = new List < object > ( ) ;
123- for ( int s = i ; s < parameters . Count ( ) ; s ++ )
133+ for ( var s = i ; s < parameters . Length ; s ++ )
124134 {
125135 convertedParams . Add ( parameters [ s ] ) ;
126136 }
127137 paramList . Add ( convertedParams . ToArray ( ) ) ;
128- break ;
129138 }
130139 else
131140 {
@@ -307,9 +316,7 @@ private static JavascriptMethod CreateJavaScriptMethod(MethodInfo methodInfo, bo
307316 jsMethod . ParameterCount = methodInfo . GetParameters ( ) . Length ;
308317 jsMethod . MethodParameters = methodInfo . GetParameters ( )
309318 . Select ( t => new MethodParameter ( )
310- { Name = t . Name ,
311- ParameterType = t . ParameterType ,
312- Position = t . Position ,
319+ {
313320 IsParamArray = t . GetCustomAttributes ( typeof ( ParamArrayAttribute ) , false ) . Length > 0
314321 } ) . ToList ( ) ;
315322
0 commit comments