[Gtk-sharp-list] default empty protected constructors (please read this one instead of crapped previous one)

Adam Treat manyoso@yahoo.com
Sat, 13 Jul 2002 17:58:00 -0400

Hello Everyone,

I saw this and thought I'd let you know how we handle this in Qt#:

Basically, I provide a protected default constructor that takes a singleton 
valuetype as a parameter.  This is an internal struct that won't get in the 
way of any future parameters, ie you won't ever need a ctor with this same 
signature ;-)  It's a value type so it can be differentiated from a null 
type.  This way you can still pass null in public constructors if you need 
to.  Here is the code for the singleton value-type:

namespace Qt {

        using Qt;
        using System;

        internal struct QNull {

                private static readonly QNull instance = new QNull (null);

                private QNull (Object dummy) {}

                internal static QNull Instance {
                        get {return instance;}

So your constructors can call something like this:

public QImage () : base (QNull.Instance)

Now, if I try QImage (null) this will not interfere because QNull.Instance is 
a value type and null is a reference.

Hope this helps,


On 12 Jul 2002, Radek [ISO-8859-1] Doulík wrote:

> why do we have constructors like this one?
> protected ScrolledWindow() : base(){}

If a class doesn't have a void ctor, we generate the above so that it can
be subclassed easily. I know this messes with customization possibilities,
because at one point I attempted to add a void Window ctor in a .custom
> I would like to add new constructor to ScrolledWindow, but I can't do it
> yet because of mentioned protected one.
> public ScrolledWindow () : this (new Adjustment (IntPtr.Zero), new 
Adjustment (IntPtr.Zero)) {}

I know I suggested this on IRC last night, but thinking about it further, it
won't work.  We need null handling to do this right.  I logged a bug for null
handling already, but you might want to make a note that ScrolledWindow is a 
good test case.  :)

Since providing simplified "default" ctors is likely to be a common 
customization, I'm thinking it might be worth adding a metadata category for
defining default parameter values for existing ctors.