[IronPython] Calling functions in IronPython that don't really exist

Jeff Slutter jslutter at reactorzero.com
Thu Dec 4 13:59:24 PST 2008


Actually this doesn't exactly work. If I want the command to be able to
return a value, I can't go with the constructor route:

res = AddNumbers( 3, 5 );

you want res equal to "8", but really it is an instance of my AddNumbers
class. I don't want the script writers to be able to save this class
instance, and it would be 'ugly' if they had to call ".GetReturn()" to
get the return value of the command.

And I don't want the call to "Do" to be explicit.

I sound really picky...


Dino Viehland wrote:
> Do you mean you'd call it like "AddNumbers().Do(3, 4)"?
>
> This is really easy.  Make AddNumbers public, then do:
>
> import clr
> clr.AddReference('MyAssembly')
> import AddNumbers
> AddNumbers().Do(3, 4)
>
> If you really want to do AddNumbers(3, 4) then you'd just write it as:
>
> public class AddNumbers
> {
>     public AddNumbers(params object[] args) {
>          Do(args);
>     }
>     public string Do( params object[] args )
>     {
>         ..check args..
>         ..add the two arguments..
>         ..return the result as a string..
>     }
> }
>
> And do the same:
>
> import clr
> clr.AddReference('MyAssembly')
> import AddNumbers
> AddNumbers(3, 4)
>


More information about the Users mailing list