[IronPython] Type analysis of expression
Lepisto, Stephen P
stephen.p.lepisto at intel.com
Mon Oct 19 16:08:26 CEST 2009
What about treating the return type of the python expression as object then coerce the object into the type required by the database? If the coercion fails, then that could be treated as a type error.
For example, after using python to evaluate the expression '2+(4*5)', the returned object could be converted to an integer using System.Convert.ToInt32() or to a string with System.Convert.ToString(). System.Convert throws InvalidCastException for those cases that cannot be converted.
-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
Sent: Monday, October 19, 2009 4:21 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Type analysis of expression
Christian Schmidt wrote:
> Hello,
>
> we are using IronPython embedded into our application to evaluate user
> defined expression. The "variables" used in the expressions are strongly
> typed and the results need to be written back into a database.
>
> I know that the return type of a dynamic expression cannot be determined
> in general. But what would be a pragmatic way to guess the return type
> of an expression?
Hehe. If you're evaluating arbitrary functions provided by the user then
I don't know of any way of 'inferring' the return type - beyond parsing
it and modelling the type flow through the expression (which would be a
lot of work).
All the best,
Michael
>
> Thanks,
> Christian
>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Ironpython-users
mailing list