使用window.external JavaScript的Date对象传递到C#WebBrowser控件 [英] Passing javascript Date object to C# WebBrowser control using window.external
问题描述
我能够调用 WebBrowser.ObjectForScripting
用JavaScript C#方法 window.external
从 web浏览器
的WinForms控制,并通过字符串
, INT
,布尔
等,但我不知道如何通过JavaScript的日期
对象,并以某种方式转换/元帅到.NET 日期时间
类。
I am able to call C# methods of WebBrowser.ObjectForScripting
with javascript window.external
from WebBrowser
WinForms control and pass string
, int
, bool
etc. However I don't know how to pass javascript Date
object and somehow convert/marshal it to .NET DateTime
class.
很显然,我可以通过一个字符串
并解析它,但是这是真的不是重点。我只是好奇,我怎么能做到这一点的JavaScript 日期
和.NET 的DateTime
?
Obviously, I could pass a string
and parse it, but this is really not the point. I'm just curious how could I do it with javascript Date
and .NET DateTime
?
推荐答案
我终于得到了它的工作。我不知道为什么,但我无法使用它与动态
。这里是解决方案:
I finally got it working. I don't know why, but I am unable to use it with dynamic
. Here is the solution:
[ComVisible(true)]
public class Foo
{
public void Bar(object o)
{
var dateTime = (DateTime)o.GetType().InvokeMember("getVarDate", BindingFlags.InvokeMethod, null, o, null);
Console.WriteLine(dateTime);
}
}
这篇关于使用window.external JavaScript的Date对象传递到C#WebBrowser控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!