[IronPython] Constructor overloading

Dino Viehland dinov at exchange.microsoft.com
Wed Jul 5 18:39:29 CEST 2006

To do typeof you can do:

import clr

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:


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:


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

Andrzej Krzywda

users mailing list
users at lists.ironpython.com

More information about the Ironpython-users mailing list