This documentation is archived and is not being maintained.

NestedContainer Class

Provides the base implementation for the INestedContainer interface, which enables containers to have an owning component.


Namespace:  System.ComponentModel
Assembly:  System (in System.dll)

[HostProtectionAttribute(SecurityAction.LinkDemand, SharedState = true)]
public class NestedContainer : Container, 
	INestedContainer, IContainer, IDisposable

The NestedContainer type exposes the following members.

Public methodNestedContainerInitializes a new instance of the NestedContainer class.

Public propertyComponentsGets all the components in the Container. (Inherited from Container.)
Public propertyOwnerGets the owning component for this nested container.
Protected propertyOwnerNameGets the name of the owning component.

Public methodAdd(IComponent)Adds the specified Component to the Container. The component is unnamed. (Inherited from Container.)
Public methodAdd(IComponent, String)Adds the specified Component to the Container and assigns it a name. (Inherited from Container.)
Protected methodCreateSiteCreates a site for the component within the container. (Overrides Container.CreateSite(IComponent, String).)
Public methodDispose()Releases all resources used by the Container. (Inherited from Container.)
Protected methodDispose(Boolean)Releases the resources used by the nested container. (Overrides Container.Dispose(Boolean).)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeReleases unmanaged resources and performs other cleanup operations before the Container is reclaimed by garbage collection. (Inherited from Container.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Protected methodGetServiceGets the service object of the specified type, if it is available. (Overrides Container.GetService(Type).)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodRemoveRemoves a component from the Container. (Inherited from Container.)
Protected methodRemoveWithoutUnsitingRemoves a component from the Container without setting Site to null. (Inherited from Container.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Protected methodValidateNameDetermines whether the component name is unique for this container. (Inherited from Container.)

The NestedContainer class is a simple implementation of the INestedContainer interface, which defines a component that logically contains zero or more other components and is owned by a parent component. The behavior of nested containers differs from a standard Container in a number of ways, including the following:

  • Site characteristics such as DesignMode and GetService are routed through the owning component’s site.

  • The site’s Name property is a qualified name that includes the owning component’s name followed by a period (.) and the child component’s name.

  • GetService provides support for the INestedContainer as a service.

  • When the owning component is disposed, the container is disposed as well.

In addition, designers treat nested containers differently. A designer host is only interested in one container—the one associated with the host. Therefore, component add and remove events are not raised when a component is added to or removed from a nested container. However, because services flow through to the nested container, component change events are raised when a component in a nested container is changed.

This disparity in event tracking also impacts undo functionality, which is closely tied to serialization. The standard undo engine uses IReferenceService to track changes made to components. If the undo engine cannot identify a name for a component through the reference service, the engine will ignore any changes for that component. This service automatically recognizes changes to contained components only if they are exposed as public read-only properties of the same name in their owners. Otherwise, the developer must pass component change events up to the owner. For example, if a nested component’s Text property is resurfaced on its owning component as an Address property, when the Text property is changed, a property change must be programmatically made for the corresponding Address property or else that change will not be tracked by undo.


The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: SharedState. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.