@@ -104,32 +104,32 @@ public bool TryCallMethod(long objectId, string name, object[] parameters, out o
104104
105105 try
106106 {
107- //Added param array support. Current implementation support param Object only. 04/04/2016
107+ //Added param array support #1644
108108 var missingParams = method . ParameterCount - parameters . Length ;
109109 //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.
110+ // number of parameters on the bound object method. (This is relevant for methods that have default values)
111111 //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 )
112+ if ( missingParams > 0 || method . HasParamArray )
113113 {
114- var paramList = new List < object > ( method . MethodParameters . Count ) ;
114+ var paramList = new List < object > ( method . Parameters . Count ) ;
115115
116116 //Loop through all of the method parameters on the bound object.
117- for ( var i = 0 ; i < method . MethodParameters . Count ; i ++ )
117+ for ( var i = 0 ; i < method . Parameters . Count ; i ++ )
118118 {
119119 //Attempt to get the javascript function param at the current bound object parameter index.
120120 //If the javascript function param is missing IE: NULL, then add Type.Missing.
121121 //This will allow for default bound object parameters. IE: (string someParameter = "someValue")
122- object jsParam = parameters . ElementAtOrDefault ( i ) ;
123- if ( jsParam == null && ! method . MethodParameters [ i ] . IsParamArray )
122+ var jsParam = parameters . ElementAtOrDefault ( i ) ;
123+ if ( jsParam == null && ! method . Parameters [ i ] . IsParamArray )
124124 {
125125 paramList . Add ( Type . Missing ) ;
126126 }
127127 //If the method parameter is a paramArray IE: (params Object[] someParameter)
128128 //grab the parameters from the javascript function starting at the current bound object parameter index
129129 //and add create an array that will be passed in as the last bound object method parameter.
130- else if ( method . MethodParameters [ i ] . IsParamArray )
130+ else if ( method . Parameters [ i ] . IsParamArray )
131131 {
132- List < object > convertedParams = new List < object > ( ) ;
132+ var convertedParams = new List < object > ( ) ;
133133 for ( var s = i ; s < parameters . Length ; s ++ )
134134 {
135135 convertedParams . Add ( parameters [ s ] ) ;
@@ -314,12 +314,13 @@ private static JavascriptMethod CreateJavaScriptMethod(MethodInfo methodInfo, bo
314314 jsMethod . JavascriptName = GetJavascriptName ( methodInfo . Name , camelCaseJavascriptNames ) ;
315315 jsMethod . Function = methodInfo . Invoke ;
316316 jsMethod . ParameterCount = methodInfo . GetParameters ( ) . Length ;
317- jsMethod . MethodParameters = methodInfo . GetParameters ( )
317+ jsMethod . Parameters = methodInfo . GetParameters ( )
318318 . Select ( t => new MethodParameter ( )
319319 {
320320 IsParamArray = t . GetCustomAttributes ( typeof ( ParamArrayAttribute ) , false ) . Length > 0
321321 } ) . ToList ( ) ;
322-
322+ //Pre compute HasParamArray for a very minor performance gain
323+ jsMethod . HasParamArray = jsMethod . Parameters . LastOrDefault ( t => t . IsParamArray ) != null ;
323324
324325 return jsMethod ;
325326 }
0 commit comments