开发者

how to convert “var f = userState as Fault” from c# to ironpython

开发者 https://www.devze.com 2023-02-04 21:04 出处:网络
I want to convert C# statement var f = userState as Fa开发者_运维技巧ult to ironpython statementThere are two parts to this.

I want to convert C# statement

   var f = userState as Fa开发者_运维技巧ult

to ironpython statement


There are two parts to this.

If you are just trying to cast userState to a Fault then you don't need to do anything as Python is weakly typed.

If you are trying to determine if userState is of type Fault then try this

from System import *
if userState.GetType() == Type.GetType(Fault):
    ...


Without seeing the next line, it's hard to know what your intent is.

If you're downcasting (say from object to Fault) - you don't have to! In IronPython members are looked up at runtime, so if userState is already a Fault you can treat it as one without any casting.

If you're trying to trigger an explicit/implicit conversion, use clr.Convert.

If you're checking if userState is a Fault, use isinstance(userState, Fault).

0

精彩评论

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

关注公众号