PC Review


Reply
Thread Tools Rate Thread

Component constructor in .NET 2.0

 
 
Edward Diener
Guest
Posts: n/a
 
      11th Apr 2006
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 ?
 
Reply With Quote
 
 
 
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      11th Apr 2006
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


 
Reply With Quote
 
Edward Diener
Guest
Posts: n/a
 
      11th Apr 2006
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.
 
Reply With Quote
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      11th Apr 2006
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.

-cd


 
Reply With Quote
 
Edward Diener
Guest
Posts: n/a
 
      11th Apr 2006
Carl Daniel [VC++ MVP] wrote:
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# constructor best practice: how much logic to place in a C#constructor Jon Microsoft C# .NET 2 11th Nov 2009 09:18 PM
Referencing a Host Form from a Custom Component constructor =?Utf-8?B?TmF0aGFu?= Microsoft Dot NET Framework Forms 0 19th Mar 2007 10:22 AM
Calling a struct constructor in a class constructor body Karl M Microsoft VC .NET 4 19th Dec 2004 01:21 PM
Enabling tracing in the constructor of a component class =?Utf-8?B?U3RhbmxleSBBbGV4?= Microsoft ASP .NET 0 1st Dec 2004 09:53 PM
Calling overloaded constructor with values inside another constructor Tristan Microsoft C# .NET 2 30th Mar 2004 01:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:22 PM.