开发者

a way to check for the existence of a function in the document and window object in Script#

开发者 https://www.devze.com 2023-04-12 13:26 出处:网络
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:

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"))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号