[英]How to obtain a proper C# string array from a JavaScript function call using Jint
I'm using Jint to evaluate JavaScript within a C# application. 我正在使用Jint在C#应用程序中评估JavaScript。 My JS returns an array of strings: 我的JS返回一个字符串数组:
return ["blah", "blah", "blah"];
But I'm not sure how to properly use that array once I'm back in C#: 但是我不确定回到C#后如何正确使用该数组:
Object result = e.Execute (javaScript).Invoke("jsFunction", answers).ToObject();
string[] resultAsStrings = ???;
Here's what the debugger looks like: 这是调试器的外观:
You can just cast the result of ToObject()
to an object[]
in this case. 在这种情况下,您可以将ToObject()
的结果ToObject()
转换为object[]
。
Here are the transformations that ToObject()
applies when facing a JavaScript value: 以下是当面对JavaScript值时ToObject()
应用的转换:
undefined
: null
undefined
: null
null
: null
null
: null
Boolean
: bool
Boolean
: bool
String
: string
String
: string
Number
: double
Number
: double
Array
: object[]
with each element itself converted using ToObject()
Array
: object[]
,每个元素本身使用ToObject()
转换 Date
: DateTime
Date
: DateTime
Function
: Func<JsValue, JsValue[], JsValue>
Function
: Func<JsValue, JsValue[], JsValue>
RegExp
: Regex
RegExp
:正则Regex
Object
: dynamic
with all the properties of the object converted using ToObject()
Object
: dynamic
具有使用ToObject()
转换的对象的所有属性 If no type is matching, it throws ArgumentOutOfRangeException
如果没有匹配的类型,则抛出ArgumentOutOfRangeException
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.