Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Passing an array in Clearscript to a C# object

$
0
0
Hi, I have a c# object I'm adding to the clearscript V8 engine that looks like this:

public class Helpers
{
...
    public int NTimes(int[] values, int targetValue)
    {
        int answer = 0;
        if (values != null)
        {
            foreach (int val in values)
            {
                if (val == targetValue)
                    answer++;
            }
        }

        return answer;
    }
}

I add the helpers class (which contains this function) using this: JavascriptContext.AddHostObject("Helpers", Helpers);


However, when in my javascript I attempt to run code like below I get an argument mismatch exception:

var items = [$A1, $A2, $A3, $A6, $A9, $A12, $A13, $A16, $A19];

var value = Helpers.NTimes(items, 3);


Is this at all related to this thread:
https://clearscript.codeplex.com/discussions/537917

Thank you!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>