System.ComponentModel.ISite Interface

Assembly: System.dll
Namespace: System.ComponentModel
Summary
Provides functionality required by sites.
C# Syntax:
public interface ISite : IServiceProvider
Remarks
Sites bind a Component to a Container and enable communication between them, as well as provide a way for the container to manage its components.

Sites can also serve as a repository for container-specific, per-component information, such as the component name.



Notes to implementors: To be a site, a class must implement the ISite interface.
Example
	/// <summary>
	/// The following example demonstrates the implementation of 
	/// ISite, IComponent, and IContainer for use in a simple library container.
	///
	/// This example uses the System, System.ComponentModel, and System.Collections
	/// namespaces.
	/// </summary>

	//This code segment implements the ISite and IComponent interfaces.
	//The implementation of the IContainer interface can be seen in the documentation 
	//of IContainer.

	//Implement the ISite interface.

	// The ISBNSite class represents the ISBN name of the book component
	class ISBNSite : ISite
	{
		private IComponent m_curComponent;
		private IContainer m_curContainer;
		private bool m_bDesignMode;
		private string m_ISBNCmpName;

		public ISBNSite(IContainer actvCntr, IComponent prntCmpnt)
		{
			m_curComponent = prntCmpnt;
			m_curContainer = actvCntr;
			m_bDesignMode = false;
			m_ISBNCmpName = null;
		}

		//Support the ISite interface.
		public virtual IComponent Component
		{
			get
			{
				return m_curComponent;
			}
		}

		public virtual IContainer Container
		{
			get
			{
				return m_curContainer;
			}
		}
		
		public virtual bool DesignMode
		{
			get
			{
				return m_bDesignMode;
			}
		}

		public virtual string Name
		{
			get
			{
				return m_ISBNCmpName;
			}

			set
			{
				m_ISBNCmpName = value;
			}
		}

		//Support the IServiceProvider interface.
		public virtual object GetService(Type serviceType)
		{
			// we are not using any service objects in this example.
			return null;
		}

	}

	// The BookComponent class represents the book component of the library container.
	
	// This class implements the IComponent interface.
	
	class BookComponent : IComponent
	{
		public event EventHandler Disposed;
		private ISite m_curISBNSite;
		private string m_bookTitle;
		private string m_bookAuthor;

		public BookComponent(string Title, string Author)
		{
			m_curISBNSite = null;
			Disposed = null;
			m_bookTitle = Title;
			m_bookAuthor = Author;
		}

		public string Title
		{
			get
			{
				return m_bookTitle;
			}
		}

		public string Author
		{
			get
			{
				return m_bookAuthor;
			}
		}

		public virtual void Dispose()
		{	
			//There is nothing to clean.
			if(Disposed != null)
				Disposed(this,EventArgs.Empty);
		}

		public virtual ISite Site
		{
			get
			{
				return m_curISBNSite;
			}
			set
			{
				m_curISBNSite = value;
			}
		}

		public override bool Equals(object cmp)
		{
			BookComponent cmpObj = (BookComponent)cmp;
			if(this.Title.Equals(cmpObj.Title) && this.Author.Equals(cmpObj.Author))
				return true;

			return false;
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}
	}

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

System.ComponentModel.ISite Member List:

Public Properties
Component Read-only

Gets the component associated with the ISite when implemented by a class.
Container Read-only

Gets the IContainer associated with the ISite when implemented by a class.
DesignMode Read-only

Determines whether the component is in design mode when implemented by a class.
Name Read-write

Hierarchy:


System.ComponentModel.ISite Member Details

Property: Component (read-only)
Summary
Gets the component associated with the ISite when implemented by a class.
C# Syntax:
IComponent Component {get;}
Remarks
A valid value for this property (that is, the value is not null) indicates that the component has been added to a container.

Return to top


Property: Container (read-only)
Summary
Gets the IContainer associated with the ISite when implemented by a class.
C# Syntax:
IContainer Container {get;}
Remarks
null for the ISite.Container property indicates that the IComponent instance does not have an ISite.

Return to top


Property: DesignMode (read-only)
Summary
Determines whether the component is in design mode when implemented by a class.
C# Syntax:
bool DesignMode {get;}
Remarks
The design mode indicator is stored in the ISite; therefore, if the Component does not have an ISite associated with it, this property is always false.

Return to top


Property: Name (read-write)
Summary
Gets or sets the name of the component associated with the ISite when implemented by a class.
C# Syntax:
string Name {get; set;}
Remarks
The components within a container might or might not be named. If a component is given a name, the name must be unique among all the components within the container.

Return to top


Top of page

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