This is a silly question, but you can use this code to check if something is a particular type...
if (child is IContainer) { //....
Is ther
The way you have it is fine but you could create a set of extension methods to make "a more elegant way to check for the 'NOT' instance."
public static bool Is(this object myObject)
{
return (myObject is T);
}
public static bool IsNot(this object myObject)
{
return !(myObject is T);
}
Then you could write:
if (child.IsNot())
{
// child is not an IContainer
}