@@ -104,30 +104,21 @@ public bool TryCallMethod(long objectId, string name, object[] parameters, out o
104104
105105 try
106106 {
107- //Added param array support #1644
108- var missingParams = method . ParameterCount - parameters . Length ;
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. (This is relevant for methods that have default values)
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 . HasParamArray )
107+ //Check if the bound object method contains a ParamArray as the last parameter on the method signature.
108+ //NOTE: No additional parameters are permitted after the params keyword in a method declaration,
109+ //and only one params keyword is permitted in a method declaration.
110+ //https://msdn.microsoft.com/en-AU/library/w5zay9db.aspx
111+ if ( method . HasParamArray )
113112 {
114113 var paramList = new List < object > ( method . Parameters . Count ) ;
115114
116115 //Loop through all of the method parameters on the bound object.
117116 for ( var i = 0 ; i < method . Parameters . Count ; i ++ )
118117 {
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")
122- var jsParam = parameters . ElementAtOrDefault ( i ) ;
123- if ( jsParam == null && ! method . Parameters [ i ] . IsParamArray )
124- {
125- paramList . Add ( Type . Missing ) ;
126- }
127- //If the method parameter is a paramArray IE: (params Object[] someParameter)
118+ //If the method parameter is a paramArray IE: (params string[] args)
128119 //grab the parameters from the javascript function starting at the current bound object parameter index
129120 //and add create an array that will be passed in as the last bound object method parameter.
130- else if ( method . Parameters [ i ] . IsParamArray )
121+ if ( method . Parameters [ i ] . IsParamArray )
131122 {
132123 var convertedParams = new List < object > ( ) ;
133124 for ( var s = i ; s < parameters . Length ; s ++ )
@@ -138,12 +129,30 @@ public bool TryCallMethod(long objectId, string name, object[] parameters, out o
138129 }
139130 else
140131 {
132+ var jsParam = parameters . ElementAtOrDefault ( i ) ;
141133 paramList . Add ( jsParam ) ;
142134 }
143135 }
144136
145137 parameters = paramList . ToArray ( ) ;
146138 }
139+
140+ //Check for parameter count missmatch between the parameters on the javascript function and the
141+ //number of parameters on the bound object method. (This is relevant for methods that have default values)
142+ //NOTE it's possible to have default params and a paramArray, so check missing params last
143+ var missingParams = method . ParameterCount - parameters . Length ;
144+
145+ if ( missingParams > 0 )
146+ {
147+ var paramList = new List < object > ( parameters ) ;
148+
149+ for ( var i = 0 ; i < missingParams ; i ++ )
150+ {
151+ paramList . Add ( Type . Missing ) ;
152+ }
153+
154+ parameters = paramList . ToArray ( ) ;
155+ }
147156
148157 try
149158 {
0 commit comments