0

I want to convert C# statement

   var f = userState as Fault

to ironpython statement

ksmakkapawee
  • 275
  • 1
  • 4
  • 10

2 Answers2

1

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):
    ...
James Gaunt
  • 14,631
  • 2
  • 39
  • 57
  • 2
    Not weakly typed, dynamically typed. Weak typing is a horrible concept that should only exist in terrible scripting languages. – leppie Jan 17 '11 at 10:05
0

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).

Community
  • 1
  • 1
Jeff Hardy
  • 7,632
  • 24
  • 24