In IronPython an assignment to a local/global variable will never perform a 
conversion.  In your C# code the conversion has to happen because the variable 
you're assigning to is typed as double.

To force the conversion you should be able to do float(obj.M1.M2.M3) or you can 
use the clr.Convert function.

From: ironpython-users-bounces+dinov=microsoft....@python.org 
[mailto:ironpython-users-bounces+dinov=microsoft....@python.org] On Behalf Of 
zxpatric
Sent: Friday, June 24, 2011 1:00 PM
To: ironpython-users@python.org
Subject: [Ironpython-users] DynamicObjects.TryConvert not called in IronPython?

Hi,

I am doing the similar thing as in 
"http://blogs.msdn.com/b/csharpfaq/archive/2009/10/19/dynamic-in-c-4-0-creating-wrappers-with-dynamicobject.aspx";
 to first convert any member into an object and then expect the 
object.TryConvert to handle the final convert. However, what is working in C# 
as double a = obj.M1.M2.M3 (return instance of Type C3, which has the 
TryConvert to convert it to double type) doesn't work in IronPython. The last 
step of converting instance of C3 to double in C3.TryConvert never happens.  I 
am currently using IronPython 2.7.0.40. Is this a known issue that has been 
addressed in 2.7.1 Beta?

Thanks
-Patrick
_______________________________________________
Ironpython-users mailing list
Ironpython-users@python.org
http://mail.python.org/mailman/listinfo/ironpython-users

Reply via email to