Component constructor in .NET 2.0

E

Edward Diener

I looked in the documentation for System.ComponentModel.Component's
constructor but I only noticed a constructor taking no parameters. My
understanding is that there is a second constructor which takes a
System.ComponentModel.IContainer interface object. Has this been the
case in previous .NET releases and has this changed with .NET 2.0 ?
 
C

Carl Daniel [VC++ MVP]

Edward said:
I looked in the documentation for System.ComponentModel.Component's
constructor but I only noticed a constructor taking no parameters. My
understanding is that there is a second constructor which takes a
System.ComponentModel.IContainer interface object. Has this been the
case in previous .NET releases and has this changed with .NET 2.0 ?

Ildasm shows only the no-args constructor for V1.1 and V2.0. Why do you
believe there's another constructor?

-cd
 
E

Edward Diener

Carl said:
Ildasm shows only the no-args constructor for V1.1 and V2.0. Why do you
believe there's another constructor?

If I use VS2005 to generate a component class, it creates both a no
argument constructor and a constructor which takes a
System.ComponentModel.IContainer container interface with the comment

"///
/// Required for Windows.Forms Class Composition Designer support
///"

This leads me to believe that all component derived classes need to
specify this second constructor. As a component developer I have added
this second constructor to all my components, with the appropriate logic
of adding the component to the container passed in the constructor. Is
this necessary ? What is the story with this second constructor ? I
could find no documentation regarding it in the VS2005 doc for any .NET
component classes.
 
C

Carl Daniel [VC++ MVP]

Edward said:
If I use VS2005 to generate a component class, it creates both a no
argument constructor and a constructor which takes a
System.ComponentModel.IContainer container interface with the comment

"///
/// Required for Windows.Forms Class Composition Designer support
///"

This leads me to believe that all component derived classes need to
specify this second constructor. As a component developer I have added
this second constructor to all my components, with the appropriate
logic of adding the component to the container passed in the
constructor. Is this necessary ? What is the story with this second
constructor ? I could find no documentation regarding it in the
VS2005 doc for any .NET component classes.

IIUC, it has no function outside the windows forms designer - effectively an
internal implementation detail of the designer that leaks into your code.

-cd
 
E

Edward Diener

Carl said:
IIUC, it has no function outside the windows forms designer - effectively an
internal implementation detail of the designer that leaks into your code.

So you are saying that the windows form designer uses this second
constructor if it is present but uses the normal no-args constructor if
it is not ? Still I think it should be documented in the .NET API so
that component developers will understand that it is being used by
components distributed by Microsoft and that they should use the same
technique in order to work well with the windows form designer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top