System.ComponentModel.Container Class

Assembly: System.dll
Namespace: System.ComponentModel
Summary
Encapsulates zero or more components.
C# Syntax:
public class Container : IContainer, IDisposable
Remarks
The Container class is the default implementation for the IContainer interface.

Containers are objects that encapsulate and track zero or more components. In this context, containment refers to logical containment, not visual containment. You can use components and containers in a variety of scenarios, including scenarios that are both visual and not visual.

The components in a container are tracked in a first-in, first-out list, which also defines the order of the components within the container. Added components are appended to the end of the list.

See also:
System.ComponentModel Namespace | IContainer | IComponent | Component

System.ComponentModel.Container Member List:

Public Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Public Properties
Components Read-only

Gets all the components in the Container.
Public Methods
Add Overloaded:
Add(IComponent component)

Adds the specified Component to the Container. The component is unnamed.
Add Overloaded:
Add(IComponent component, string name)

Adds the specified Component to the Container and assigns it a name.
Dispose Overloaded:
Dispose()

Releases all resources used by the Container.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
Remove Removes a component from the Container.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
CreateSite Creates a site ISite for the given IComponent and assigns the given name to the site.
Dispose Overloaded:
Dispose(bool disposing)

Releases the unmanaged resources used by the Container and optionally releases the managed resources.
Finalize Overridden:
GetService Gets the service object of the specified type, if it is available.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.ComponentModel.Container Member Details

ctor #1
Summary:
Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public Container();

Return to top


Property: Components (read-only)
Summary
Gets all the components in the Container.
C# Syntax:
public virtual ComponentCollection Components {get;}
Implements:
IContainer.Components
Remarks
This method can be overridden by a derived class.

The components in the collection are stored in the same order as they were added to the Container.

Return to top


Overloaded Method: Add(
   IComponent component
)
Summary
Adds the specified Component to the Container. The component is unnamed.
C# Syntax:
public virtual void Add(
   IComponent component
);
Parameters:

component

The component to add.

Implements:
IContainer.Add
Remarks
This method can be overridden by a derived class.

The new Component is added to the end of the list.

See also:
Container.Remove

Return to top


Overloaded Method: Add(
   IComponent component,
   string name
)
Summary
Adds the specified Component to the Container and assigns it a name.
C# Syntax:
public virtual void Add(
   IComponent component,
   string name
);
Parameters:

component

The component to add.

name

The unique, case insensitive name to assign to the component.

-or-

null that leaves the component unnamed.

The unique, case insensitive name to assign to the component.

-or-

null that leaves the component unnamed.

Exceptions
Exception Type Condition
ArgumentException The name parameter is a duplicate.
Implements:
IContainer.Add
Remarks
This method can be overridden by a derived class.

The new Component is added to the end of the list.

See also:
Container.Remove

Return to top


Method: CreateSite(
   IComponent component,
   string name
)
Summary
Creates a site ISite for the given IComponent and assigns the given name to the site.
C# Syntax:
protected virtual ISite CreateSite(
   IComponent component,
   string name
);
Parameters:

component

The IComponent to create a site for.

name

The name to assign to component; or null to skip the name assignment.

Return Value:
The newly created site.
Remarks
If name is null the IComponent is added to the Container without an identifying name.

This method can be overridden by a derived class. Implementors wishing to override Container.CreateSite can provide a custom implementation through a class implementing ISite.

Return to top


Overloaded Method: Dispose()
Summary
Releases all resources used by the Container.
C# Syntax:
public void Dispose();
Implements:
IDisposable.Dispose
Remarks
Calling Container.Dispose allows the resources used by the Container to be reallocated for other purposes. For more information about Container.Dispose, see the conceptual topic at MSDN: cleaningupunmanagedresources.

Return to top


Overloaded Method: Dispose(
   bool disposing
)
Summary
Releases the unmanaged resources used by the Container and optionally releases the managed resources.
C# Syntax:
protected virtual void Dispose(
   bool disposing
);
Parameters:

disposing

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks
When the disposing parameter is true, this method releases all resources held by any managed objects that this Container references. This method invokes the Dispose() method of each referenced object.

Notes to inheritors: Dispose can be called multiple times by other objects. When overriding Dispose(Boolean), be careful not to reference objects that have been previously disposed of in an earlier call to Dispose. For more information about how to implement Dispose(Boolean), see the conceptual topic at MSDN: implementingdisposemethod.

For more information about Dispose and Object.Finalize, see the conceptual topic at MSDN: cleaningupunmanagedresources and the conceptual topic at MSDN: overridingfinalizemethod.

This method is called by the public Dispose method and the Object.Finalize method.Dispose() invokes the protected Dispose(Boolean) method with the disposing parameter set to true. Object.Finalize invokes Dispose with disposing set to false.

When the disposing parameter is true, this method releases all resources held by any managed objects that this Container references. This method invokes the Dispose() method of each referenced object.



Notes to inheritors: Dispose can be called multiple times by other objects. When overriding Dispose(Boolean), be careful not to reference objects that have been previously disposed of in an earlier call to Dispose. For more information about how to implement Dispose(Boolean), see the conceptual topic at MSDN: implementingdisposemethod.

For more information about Dispose and Object.Finalize, see the conceptual topic at MSDN: cleaningupunmanagedresources and the conceptual topic at MSDN: overridingfinalizemethod.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: Finalize()
C# Syntax:
~Container();
Remarks
Calls Dispose (disposing) with disposing set to false to free unmanaged resources.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetService(
   Type service
)
Summary
Gets the service object of the specified type, if it is available.
C# Syntax:
protected virtual object GetService(
   Type service
);
Parameters:

service

The Type of the service to retrieve.

Return Value:
An Object implementing the requested service, or null if the service cannot be resolved.
Remarks
The default implementation of this method returns null. Implementors can override this method to provide a custom implementation to return a service object. For more information, see IServiceProvider.GetService.
See also:
IServiceProvider

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Remove(
   IComponent component
)
Summary
Removes a component from the Container.
C# Syntax:
public virtual void Remove(
   IComponent component
);
Parameters:

component

The component to remove.

Implements:
IContainer.Remove
Remarks
This method can be overridden by a derived class.
See also:
Container.Add

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.