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

I want to convert C# statement

var f = userState as Fault

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

Category:c# Time:2011-01-17 Views:0

Related post

  • Convert var to DataTable 2010-05-13

    I have var item which I want to convert in to a Datatable. How can I do this. var items = (from myObj in this.Context.Orders group myObj by myObj.OrderDate.ToString("yyyy-mm") into ymGroup select new { Date = ymGroup.Key, Start = ymGroup.Min(c =>

  • Convert var latlng = $(this).attr('title') to usable coordinates for google map v3 2011-04-26

    I am trying to add a marker when a location title is clicked. The title of the span contains the coordinates in the title format 43.61243.612631631, -116.21107599999999 When I run the following code it errors out. If I actually type the coordinates i

  • Converting var data to hashtable 2011-05-09

    Is it possible to convert a var data to hashtable? Hashtable hsTest = new Hashtable(); var oFeat = (from t in db.test where t.Product_ID == iProductID select t); --------------Solutions------------- Say you want to use Product_ID as key in the hashta

  • Why doesn't the compiler convert var[] to object[] in c#? 2012-01-17

    There is no difference between these two lines, because the compiler, in the second line, understands that it is an array of type int. var x = new int[] { 1, 2, 3 }; //Fine, x is int[] var x = new [] { 1, 2, 3 }; //Fine, x is int[] But why can't I do

  • Convert "var" to explicit type in Visual Studio? 2012-02-01

    Possible Duplicate: Tool to refactor C# var to explicit type Does Visual Studio have any type of shortcut (shortcut meaning short of writing out the actual type name) that allows you to write "var" and have it converted to the actual type name? ex: v

  • convert $var of function to string? 2011-05-04

    My goal just debug function dbg($var){ echo "you have passed $var"; } call dbg($test) output: you have passed test call dbg("var") output: you have passed "var" In php .anyone could help me to do that? --------------Solutions------------- Try this if

  • How to intercept WCF faults and return custom response instead? 2011-06-10

    Consider the following very basic WCF service implementation: public enum TransactionStatus { Success = 0, Error = 1 } public class TransactionResponse { public TransactionStatus Status { get; set; } public string Message { get; set; } } [ServiceCont

  • How do I convert a List(Of T) to an ObservableCollection(Of T) in VB.NET? 2008-10-28

    Is there a way to do this without iterating through the List and adding the items to the ObservableCollection? --------------Solutions------------- No, there is no way to directly convert the list to an observable collection. You must add each item t

  • Tool to refactor C# var to explicit type 2008-11-14

    Our coding standards ask that we minimise the use of C# var (suggests limiting it's use to being in conjunction with Linq). However there are times when using generics where it's reasonably convenient e.g. Dictionary<DateTime, Dictionary<string

  • How can I convert JavaScript code into one big Java string 2009-01-13

    So I have 1000 lines of javascript. I need to turn it into a Java String so that I can output (via System.out.println or whatever). I'm looking for an online tool to escape all the quotes... something geared toward my specific need would be nice as I

  • In GNU Make, how do I convert a variable to lower case? 2009-03-20

    This is a silly question, but.... with GNU Make: VAR = MixedCaseText LOWER_VAR = $(VAR,lc) default: @echo $(VAR) @echo $(LOWER_VAR) In the above example, what's the correct syntax for converting VAR's contents to lower case? The syntax shown (and eve

  • What's the difference between dynamic(C# 4) and var? 2009-06-07

    I had read a ton of articles about that new keyword that will ship with C# v4,but I couldn't make out the difference between a "dynamic" and "var". This article made me think about it,but I still can't see any difference. Is it that you can use "var"

  • Javascript to convert Markdown/Textile to HTML (and, ideally, back to Markdown/Textile) 2009-08-23

    There are several good Javascript editors for Markdown / Textile (e.g.:, the one I'm using right now), but all I need is a Javascript function that converts a string from Markdown / Textile -> HTML and back. What's t

  • Convert date using strtotime from DOMDocument element 2010-01-15

    I'm parsing some data using DOMDocument after fetching HTML file using curl. The codes look like this $dom = new DOMDocument(); @$dom->loadHTML($content); $tables = $dom->getElementsByTagName('table'); $rows = $tables->item($tblNum)->getE

  • Convert an expression tree for a c# query expression 2010-09-08

    I am having a problem converting this query via an expression tree: WageConstIn => Convert.ToString(WageConstIn.Serialno).StartsWith("2800") This is my expression tree: var searchTextExp = LinqExpression.Constant("2800"); var parameterExp = LinqEx

  • My generic type converter smells bad, exceptions at runtime, object as catch all, boxing etc 2010-10-27

    Firstly, I've asked this question elsewhere, but seems to think that asking the same questions elsewhere is fine, so here goes. I'll update both if/when I get an answer. I'm doing a lot of conversion between simple types and I

  • C# convert RGB value to CMYK using an ICC profile? 2011-03-08

    this question seems posted at many places over the interwebs and SO, but I could not find a satisfactory answer :( How can I convert a RGB value to a CMYK value using an ICC profile? The closest answer I have is there, where it explains how to conver

  • Loading the Jira Public Certificate in .Net from a string (how to convert ASN.1 encoded SubjectPublicKeyInfo to X509 Cert in .Net) 2011-03-30

    I am building an oauth 1.0a service that will be consumed by a gadget within Jira, it's a .Net 3.5 Application written in C#. Jira makes requests to this service using the RSA-SHA1 signature method, which means to verify the signature of the request

  • How to return Faults in JSON from AJAX Enabled WCF Service? 2011-07-24

    I have an AJAX-enabled WCF service (with enableWebScript in the behavior) that has a ValidationFault which I created. Here's the service: [ServiceContract] public interface ICoreWCF { /// <summary> /// Saves the Customer. /// </summary> [

Copyright (C), All Rights Reserved.

processed in 0.860 (s). 13 q(s)