a way to check for the existence of a function in the document and window object in Script#
I am trying to convert st开发者_开发百科atements that check the existence of functions in document and window objects but I don't find any elegant form in ScriptSharp:
// Javascript expected result
if (document.getElementById)
// Current ScriptSharp
if (!Script.IsNullOrUndefined(Script.Literal("document.getElementById"))
Is there a better way that I didn't think of?
If I do something like:
if (Dictionary.GetDictionary(Document).ContainsKey("getElementById"))
I get an error because Document is a type and not an object.. is there a way to get the javascript document object?
I would recommend using Type.HasField.
if (Type.HasField(typeof(Document), "getElementById")) { ... }
Modify it to use typeof
operator
if (Dictionary.GetDictionary(typeof(Document)).ContainsKey("getElementById"))
精彩评论