[IronPython] Constructor overloading

Shri Borde Shri.Borde at microsoft.com
Wed Jul 5 22:07:51 CEST 2006


I have opened http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=794  to track this.

Do you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland
Sent: Wednesday, July 05, 2006 9:39 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Constructor overloading

To do typeof you can do:

import clr
clr.GetClrType(pythonType)

and then you can do the GetConstructor call.

There have been some recent fixes which change the way overloading constructors works - you'll want to overload __new__ and not __init__.  There was some potential for confusion here in beta 8 and earlier.

But the correct way to call it should be via new, so you should be able to do:

Class MySubClass(MyDotNetBaseClass):
        def __new__(cls, arg):
                return MyDotNetBaseClass.__new__(cls, arg)

and then to select overloads you should be able to do:

class MySubClass(MyDotNetBaseClass):
        def __new__(cls, arg):
                return MyDotNetBaseClass.__overloads__[Stream](cls, arg)


If that doesn't work for you w/ Beta 8 you might want to try downloading the latest bits and see if that fixes it for you.


-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Andrzej Krzywda
Sent: Wednesday, July 05, 2006 7:20 AM
To: Discussion of IronPython
Subject: [IronPython] Constructor overloading

Hello all,

We are trying to create a .Net type object which has several one-parameter constructors.
By default it does the wrong thing and we want to specify which constructor is called.

We tried:

Icon.__overloads__[Stream](myStream)
Icon.__init__.__new__.__overloads__[Stream](myStream)

but neither of these methods work. How can we do it?

We also attempted to work around the issue by using Reflection on the Icon class:

typeof(Icon).GetConstructor([Stream]).Invoke([myStream])

but we can't find the IronPython equivalent of typeof. Does it exist?

--
Andrzej Krzywda


_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
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