Home All Groups Group Topic Archive Search About

Component constructor in .NET 2.0

Author
11 Apr 2006 2:13 AM
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 ?

Author
11 Apr 2006 4:18 AM
Carl Daniel [VC++ MVP]
Edward Diener wrote:
> 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
Author
11 Apr 2006 11:47 AM
Edward Diener
Carl Daniel [VC++ MVP] wrote:
> Edward Diener wrote:
>> 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?

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.
Author
11 Apr 2006 2:10 PM
Carl Daniel [VC++ MVP]
Edward Diener wrote:
Show quote
> Carl Daniel [VC++ MVP] wrote:
>> Edward Diener wrote:
>>> 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?
>
> 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
Author
11 Apr 2006 2:32 PM
Edward Diener
Carl Daniel [VC++ MVP] wrote:
Show quote
> Edward Diener wrote:
>> Carl Daniel [VC++ MVP] wrote:
>>> Edward Diener wrote:
>>>> 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?
>> 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.

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.

AddThis Social Bookmark Button