Call function with multiple object parameters

Aug 11, 2010 at 12:25 PM
Edited Aug 11, 2010 at 12:26 PM

Just a small snippet used to call a JS function with several objects/non-simple parameters.


        public object CallFunction(string name, params object[] parameters)
            string parameterArrayString = "";
            for (int i = 0; i < parameters.Length; i++ ){
                jsContext.SetParameter("tempFunctionParameter" + i, parameters[i]);
                parameterArrayString += "tempFunctionParameter" + i + ",";

            parameterArrayString = parameterArrayString.Substring(0, parameterArrayString.Length - 1);

            return jsContext.Run(name + "(" + parameterArrayString + ");");

Just a temporary solution. I'm sure the team will soon implement a better solution.
Maybe already in 0.3? 


Aug 11, 2010 at 8:07 PM
Edited Aug 12, 2010 at 1:26 PM

It is a great workaround.  It probably won't be integrated as a core method however, since it was achieved so easily with external code, and with so many features and options we could put in it, creating feature extensions instead just makes sense.

Thanks for share your solution!

Aug 11, 2010 at 9:02 PM

Ok, thanks for the info.

One feature, that we would really need, is the ability to use SetParameter on a JS object we got from GetParameter.


Run("myObject = { testVar: 'someString' };");
var jsObject = GetParameter("myObject");
SetParameter(jsObject, "testVar", "someNewString");

This of course means that first the GetParameter needs to be able to return an object first :) As I understood that should be in the upcoming 0.3 right?

Thanks for the great work guys! 

Aug 12, 2010 at 1:12 PM

There are some important improvements in the incoming release, including support for conversions between Javascript objects and Dictionary<string, object> back and forth.

This should be a sufficient functionality for your needs.