Conatainer objects

  • Thread starter Thread starter WizmanG
  • Start date Start date
WizmanG said:
Is there some easy way to determine if an object is a container? I

What kind of container? Check to see if it implements IContainer?

Type t = o.GetType().GetInterface("IContainer");

if (t == null) {
// Type does not implement IContainer.
} else {
// Type implements IContainer.
}

HTH,
Mythran
 
Mythran said:
What kind of container? Check to see if it implements IContainer?

Type t = o.GetType().GetInterface("IContainer");

if (t == null) {
// Type does not implement IContainer.
} else {
// Type implements IContainer.
}

That's quite a lot of work for:

if (o is IContainer)
{
...
}
 
Jon Skeet said:
That's quite a lot of work for:

if (o is IContainer)
{
...
}

Hmm, I was sure I could do that too...but I wanted to do it the hard way???
:P Yeah, Jon's way is better... :P And that's the way I do it...wonder how
I forgot about it :P

Mythran
 

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

Back
Top