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

New Post: Using List and Linq withing javascript

$
0
0
Hello!

The method you're trying to call from script code is declared like this:
publicbool Exists(Predicate<T> match)
Because you're dealing with a string list, it requires an argument of type Predicate<string>, which is a delegate type.

The syntax p => p == child.ChildNodes[1].InnerText is C#-specific and not legal in JavaScript. Instead, you need to create the appropriate delegate around a script function.

To do that, first you need to expose the delegate type to the script engine:
engine.AddHostType("StrPred", typeof(Predicate<string>));
Now you can call the method from script code like this:
pred = function (p) { return p == child.ChildNodes[1].InnerText; };
exists = accountList.Exists(new StrPred(pred));
Good luck!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



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