我正在尝试转换检查文档和窗口对象中函数是否存在的语句,但我在ScriptSharp中找不到任何优雅的表单:
// Javascript expected result
if (document.getElementById)
// Current ScriptSharp
if (!Script.IsNullOrUndefined(Script.Literal("document.getElementById"))
有没有更好的方式我没想到?
如果我这样做:
if (Dictionary.GetDictionary(Document).ContainsKey("getElementById"))
我收到错误,因为Document是一个类型而不是一个对象..有没有办法获取javascript文档对象?
答案 0 :(得分:2)
我建议使用Type.HasField。
if (Type.HasField(typeof(Document), "getElementById")) { ... }
答案 1 :(得分:1)
修改它以使用typeof
运算符
if (Dictionary.GetDictionary(typeof(Document)).ContainsKey("getElementById"))