microsoft/ClearScript

How to use Linq in microsoft.clearscript.v8

Closed this issue · 5 comments

in this case I am use microsoft.clearscript.v8 in asp .net core mvc
this is below homecontroller.cs code

` public async Task<IActionResult> Index()
    {

        using (var engine1 = new V8ScriptEngine())
        {

            engine1.AddHostType(typeof(JavaScriptExtensions));
            
            engine1.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading;
            
            string scriptPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "js", "NewScript.js");

            string scriptContent = System.IO.File.ReadAllText(scriptPath);
                         
            engine1.Execute(scriptContent);
          
            dynamic data = engine1.Evaluate("NewLinq();");
          
            return View();

        }
}`

and this below code in NewScript.js (JavaScript file) function

`function NewLinq() {

const rawData = [
	{ "id": 1, "name": "John", "age": 25 },
	{ "id": 2, "name": "Jane", "age": 30 }		
];

var result = rawData
	.filter(person => person.age > 25);  

return result;

}`

in this code return UnderlyingSystemType = '((Microsoft.ClearScript.ScriptItem)data).UnderlyingSystemType' threw an exception of type 'System.NotImplementedException' this error how to get output and use linq

Hello @NamanGajjar26,

As with your previous sample, we tested your code and encountered no issues. Also, you aren't using Linq anywhere above, so we're not clear on how it's related.

in this code return UnderlyingSystemType = '((Microsoft.ClearScript.ScriptItem)data).UnderlyingSystemType' threw an exception of type 'System.NotImplementedException'

Again, where are you seeing this exception? How can we reproduce it? Can you provide a stack trace?

Thanks!

how to use import in this code in js file

import * as jsonpath from 'D:/VB_Programs/V8JavaJsonModify/V8JavaJsonModify/wwwroot/js/jsonpath.min.js';
function Example1() {
var cities = [
{ name: "London", "population": 8615246 },
{ name: "Berlin", "population": 3517424 },
{ name: "Madrid", "population": 3165235 },
{ name: "Rome", "population": 2870528 }
];
const result = jsonpath({ path: '$..name', cities });
return result;
}

how to use import in this code in js file

Please see here.

Please reopen this issue if you have additional questions or comments on this topic. Thanks!