Component model and ISite interface in particular

O

ozbear

I have read just about everything I can find (several times!)
on the ISite interface but still am just not getting it.

I created a new class derived from Stream. Since I wanted to
be able to drop this non-visual component on a form and set properties
at design time, I also included IComponent, i.e.,
public class SerialStream :
System.IO.Stream,System.ComponentModel.IComponent

By including the IComponent interface, this also required that
I support the ISite interface. Merely including the
declaration and properties :
private ISite serialSite;
[Browsable(false)]
public virtual ISite Site
{
get {return serialSite;}
set {serialSite = value;}
}

satisfied both the compiler as well as the IDE/designer in that
I could drop it on form, add it to the Toolbar, etc, set
other properties and successfully use the component. However,
I never instantiated a Site and serialSite was and is always null.

This apparently made no difference in /this/ class and so I am
puzzled as to why it is required at all. All the doco I have
read refers to a component to be "sited", but since my site
is always null, this doesn't help my understanding.

I guess I am asking under which circumstances the Site is actually
used by the framework and what functionality I have not provided
by never assigning a non-null Site object to my serialSite
member.

For example, is it only really required to be non-null if the
component will also house/contain components of its own?
What does the framework really use it for?

Oz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top